Character Collision

Hello Panda3D forum. I am stuck at a point where I need to add character collision in a way where the character can jump and have a jet pack etc, etc. Should I use the built in collision, or ODE physics? If someone could please point me somewhere that would be great.

Thanks,
Ion Duel

Depends. For simple gravity simulations like gravity, jetpack you really don’t need a physics engine. If you’re looking into advanced stuff like Ragdolls or so you’d need a real physics engine like ODE.

Thanks for the quick response. So, I would just need to use collisions. But where would I start? Would I use a ray or a tube or a sphere for the characters collision? I could probably figure out gravity and jumping on my own.

One or more spheres, most likely, since Tubes cannot be used as From objects and Rays are limited.

Okay, I will make it a sphere collision. Will it naturally face uphill and stuff… Because I would need a way to counteract that.

Now I cant quite figure out jumping. The collision works properly with this

self.cTrav.traverse(render)
        
        entries = []
        for i in range(self.charHandler.getNumEntries()):
            entry = self.charHandler.getEntry(i)
            entries.append(entry)
        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                     x.getSurfacePoint(render).getZ()))
        if(len(entries) > 0) and (entries[0].getIntoNode().getName() == "ground"):
            self.char.setZ(entries[0].getSurfacePoint(render).getZ())
        else:
            self.char.setPos(self.startPos)

Movement and gravity is here:

        if(self.keyMap["left"] != 0):
            self.char.setH(self.char.getH() + elapsed * 300)
        if(self.keyMap["right"] != 0):
            self.char.setH(self.char.getH() - elapsed * 300)
            
        if(self.keyMap["forward"] != 0):
            self.char.setY(self.char, -(elapsed * 10))
        if(self.keyMap["backward"] != 0):
            self.char.setY(self.char, +(elapsed * 10))
        
        self.char.setZ(self.char, -(elapsed * 10))

I dont know what code to add to make him jump. Because everything I try he stays on the ground.

I was reading through this https://discourse.panda3d.org/viewtopic.php?t=4068 but I still cant figure jumping out… If someone has some more specific info that would be greatly appreciated.

I see no code that attempts to do jump at all there?

If you want to jump, then first detect the jump key, and add some velocity to the Y direction the first frame it’s pressed after not being pressed. The trick is to remember whether the last frame had the key down or not. Also, because it’s an impulse over a single frame, the delta velocity needs to be pretty big (like, velocity.y += 5 or so, assuming feet for measurement).
Then you may want to improve it such that you can only jump when you have a ground collision – that means you have to detect the ground collision, and set a flag appropriately.

I moved my question over here: https://discourse.panda3d.org/viewtopic.php?p=36898