Finicky Controls

Remember: “set_jump” is only called once per jump. Thus putting your code there would cause it to likewise be called only once per jump.

Your “gravity” function, on the other hand, runs for the duration of a jump–and you want this movement to likewise last for the duration of the jump.

If it feels inappropriate because the method is called “gravity”, just rename the method, I’d say!

Yay I believe it worked!!!

I used this, tell me if this is what you had in mind:

 def gravity(self, task):
        self.pandaActor.setZ(self.pandaActor.getZ() + self.jump_speed * globalClock.getDt())
        if self.pandaActor.getZ() > 0:
            self.jump_speed = self.jump_speed - self.gravity_force * globalClock.getDt()
            self.pandaActor.setY(self.pandaActor, -20)
        if self.pandaActor.getZ() < 0:
            self.pandaActor.setZ(0)
            self.jump_speed = 0
            self.jump_status = False
        return task.cont

Anyways thank you so much, the solution seems easier now lel. :sweat_smile::+1:

1 Like

Yup, that looks about right!

Well done, and I’m glad that it seems to be working for you. :slight_smile:

Not right, the character will only be able to move if his position is above 0. Place the move code at the end. Or in front.

Alright let me try, seemed to work but ok.

EDIT: Serega it was right the first time, I don’t know what you’re talking about. You can pretty much leap anywhere, but when I put it at the end it completely just went back to normal straight in the air jumping.

if self.pandaActor.getZ() > 0:

What do you think this condition says?

If it’s rising above 0?

@serega-kkz: Remember: this isn’t the only place that the line in question exists. It (presumably) also exists in the general movement code. This particular line only exists to move the character horizontally while jumping.

Is moving and jumping somehow connected? more precisely the position in the object

Sort of. The problem that we’re trying to solve here is that, previously, the character would only jump directly upwards, not moving forward at all. This allows the character to move forward while jumping–to leap forward, effectively.

(A velocity-based system would likely work better, but would be more complex.)

Wait sorry, what would be the difference of the end result. The quick way(mine) compared to the velocity one?

The problem is that it works even when the character is above 0

Using a velocity would allow for a more nuanced approach, I think–would more-easily allow for things like slowing to a stop, or jumping different distances–and would remove the behaviour of turning in mid-air resulting in the direction of the character’s jump changing with the turn.

What do you mean? From what I gather of the game here, the character is only ever above 0 when jumping.

Ah I see, mine pales in comparison. But I’m satisfied for the night… :smiley:

1 Like

I mean, try it out! You may find that you’re happy with the result. Perhaps I’m being overly-attached to “my way” of doing things. :wink:

But either way, fair enough! You can perhaps work on and improve your game’s mechanics as you go forward!

No, this is part of the code condition for enabling gravity. If the character is above zero, then you need to pull him to the bottom.

True, but it’s also the task that runs during a jump, and not at other times. That makes it a (roughly) suitable place to put code related to horizontal movement during a jump, too. (If such movement isn’t to be handled in a more-general way, as is the case at the moment at least.)

I like your motivation! Anyways gotta go to sleep soon, thanks for your help :+1:

1 Like

I don’t think that the character will always be at level 0, what about the ledges, the barrels of the platform?