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:
-
I added a self.taskCount variable for keeping a number (Should always be placed as 0 first).
-
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).
-
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).
- 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
- 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.
- 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.
- 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