Noob in need of help, jumping

im trying to make my character jump. i have no jumping animation. this is my code, im using the tutorial roaming ralph as a base.

def jumpRalphJump(self):
    ralphPos = self.ralph.getPos()
    ralphPos2 = self.ralph.getPos()
    ralphPos.addZ(1)
    ralphPos.addY(-1)
    ralphPos2.addY(-2)
    self.ralph.Interval = self.ralph.posInterval(.3, ralphPos)
    self.ralph.Interval2 = self.ralph.posInterval (.3, ralphPos2)
    self.ralph.Sequence = Sequence(self.ralph.Interval, self.ralph.Interval2)
    ralphJump = self.ralph.Sequence
    self.ralph.loop('run', fromFrame = 1, toFrame = 1) 
    ralphJump.start()

i attached this to the spacebar. so i can jump, but only in 1 direction. i cant figure out how to get local coordinates for my character instead of using the world coordinates. Help!

def jumpRalphJump(self):
   ralphPos = self.ralph.getPos()
   ralphPos2 = self.ralph.getPos()
   ralphPos.addZ(1)
   ralphPos.addY(-1)
   ralphPos2.addY(-2)
   self.ralph.Interval = self.ralph.posInterval(.3, ralphPos)
   self.ralph.Interval2 = self.ralph.posInterval (.3, ralphPos2)
   self.ralph.Sequence = Sequence(self.ralph.Interval,self.ralph.Interval2)
   ralphJump = self.ralph.Sequence
   self.ralph.loop('run', fromFrame = 1, toFrame = 1)
   ralphJump.start()

First, you are getting the local coordinates of your character with “self.ralph.getPos()” If you want the global coordinates, use “self.ralph.getPos(render)”.

Second, it looks like you’re going to jump backwards since you’re using negative Y values. There could be other transforms elsewhere in the scenegraph that correct this, though, but at first glance this looks like he’ll move backwards. Positive Y points forward in Panda’s coordinate space.

Third, I’m not sure why you start looping a single frame of the “run” animation when you jump. Unless you’re blending animations, I think this will override whatever loop you have playing at the moment and continually play that single frame, effectively posing him at that frame(though I’ve never tried looping over a single frame).

Lastly, if you call this function multiple times in rapid succession, you’re going to have several of these intervals running at once, stomping on each other. Usually it’s a good idea to clean up previous intervals (either by pausing or stopping them) before losing your references to them. That way, you know you’ll only have one playing at a time. For example, even though you assign a new interval to “self.ralph.Sequence”, the one you created previously may still be playing in the interval manager. By assigning the new value to this reference, you’ve essentially lost your handle to the old one.

So that’s probably a little more than what you were looking for, but did it answer your question?

hmmm, i understand that the self.ralph.getPos() gets his coordinates in the world, but when i do ralphPos.addZ(1) or ralphPos.addY(-1) it will always add these values so he moves in the same direction. so no matter what direction my character is facing, it always adds Y values so that he moves on the “world” Y axis.

Right, he’s moving in his parent node’s coordinate system. getPos() will return positions in that coordinate system as well. Any changes to that position will be with respect to that system.

I think what you want is something like getRelativePoint()

It works like this:

ralphPos = self.ralph.getParent().getRelativePoint(self.ralph, Point3(0,-1,1))
ralphPos2 = self.ralph.getParent().getRelativePoint(self.ralph, Point3(0,-2,0))

This transforms the points (0,-1,1) and (0,-2,0) from ralph’s space into his parent’s space. Now ralphPos and ralphPos2 are the correct points of the jump in ralph’s parent’s coordinate space. This transformation is necessary since posIntervals move ralph with respect to his parent’s space.