Holding Down Key allows actor keep going up
I am trying to create a jumping effect but I cant seem to put a maximum jump height on the actor. When I press once the actor will go down. When I hold down the actor continues to go up. How can I get the actor to automatically go down regardless of how long I hold down the spacebar?
Best Answers
-
The_Gamesalad_Guru Posts: 9,922
Put in a timer that forces the actor back down after a predetermined amount of time. -
SlickZero Houston, TexasPosts: 2,870
For the basic jump function, you can do this...
Make a rule that says
when "spacebar" (or whatever) is pressed
change attribute - self.motion.linear velocity.Y to self.motion.linear velocity.Y +500 (or whatever number works best)
And to keep from having your character jumping every time you tap the spacebar, you will need to set up an attribute to see if the character is touching the ground or in the air. When the character is touching the actor that is acting as the ground, just have a boolean set to true when colliding, and in the otherwise statement, have the boolean set to false. So the script will look like this.
when "spacebar" (or whatever) is pressed and attribute "touching ground" is true
change attribute - self.motion.linear velocity.Y to self.motion.linear velocity.Y +500 (or whatever number works best)
This will keep the actor from launching completely out of the game if someone repeatedly taps the jump button.