[SOLVED]Jumping Actor

Good eye, I didn’t notice that o.o I guess I meant to type self.isRising.
Also, so if I were to move task.done and take out return task.cont, it’ll start to work properly?

And if it goes for approximately 0.15 seconds, how can I increase this time?

Again, would removing the first task.cont in my task enable me to actual move upward?
^- That’s all I really care about how to do at the moment.

I’m not home or I would test around with this.

Yeah, That does not work at all.
I tried every combination of removing, relocating, or changing my

task.cont

and

task.done

and had also fixed that

self.isRising

.
It did not work.
Everything works fine, once again, except the problem about moving upward. Still looks like i’m teleporting a few heighths up, and then teleporting back down.

I fixed it.
It’s a bit shakey, But actually works now.

Turns out I wasn’t using the math I used to use when I worked for a no-profit scripting videogame.
(Different language, same concept).

I won’t give out my full code, But for those people wanting to make a jump in the future (Mainly new people), Here you go:

  1. I added a self.taskCount variable for keeping a number (Should always be placed as 0 first).

  2. Make sure to add something like self.isRising (To tell if your character is jumping or not: Can be calld something else, Since it will go along with falling as well).

  3. If you’re using the ground collision from Roaming Ralph, I would suggest adding

if self.isRising is False:

and then your collision afterwards (To prevent your character from trying to collide onto the ground while jumping).

  1. Remember to add your “space” button or whatever else to trigger the task: If you had not already done this, Before it triggers the task, add
if self.isRising is False:

before the trigger so that you cannot jump more than once at the same time

  1. Here’s where your self.isRising and self.taskCount will come in handy. Add something like this to your task:
if self.isRising is False and self.taskCount is 0:
self.isRising = True
self.taskCount+=1
return task.cont

This is not necissarily needed, But can help make sure the next step is continued properly.

  1. The next step is pretty simple. Here we will make sure your character rises upwards a small scale at a time. Add something like:
if self.isRising is True and self.taskCount >0 and self.taskCount <=10.0: #(10 is being used as an example in this statement. This is how many times you want your character to move up before falling back down)
  self.actor.setZ(self.actor.getZ()+0.2*globalClock.getDt()) #This is also changable. 0.2 will result in moving up 2 z's overall (10 x 0.2).
  self.isRising = True
  self.taskCount+=1
  if self.isRising is True and self.taskCount <=10.0:
    return task.again
  if self.isRising is True and self.taskCount > 10.0:
    return task.cont

and viceverca for falling.

  1. After adding that and your falling statement (should be pretty similar to rising): Make sure you reset your task by adding something like:
self.isRising = False
self.taskCount = 0

Remember to only place this AFTER your falling task. This will enable you back to colliding with the ground, as originally, and enable you to jump once again after the task.

Feel free to correct me on typos or fix my code up a bit, I did not copy&paste them from my actual script, Typed them up as I went along.

Also, Sorry for a few misplacements, I was never good at typing chronological order.

-Luna

P.S. I wouldn’t have taken the time up to explain how to fix my problems, But I know how frustrating looking at posts about problems can be when people say “Nevermind, fixed it” without and explination on how they did it (For those who may have the same problem). I encourage anyone reading this to do the same :smiley:

Congratulations.

Last note from me: keep in mind that animating by frames rather than by time makes the animation framerate dependent. That said your jump will be ten times faster when running on 300 FPS than on 30 FPS. That’s actually the reason for people to use the globalClock.getDt()

Oh wow, Thanks. I did however, use globalClock.getDt() in my script for jumping. Guess I forgot to put it in my steps. I did edit it and added that to it, so thanks.