Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How can I make an object jump at the same height by applying the same force?

$
0
0
I'm working on a 2D game, when the user hits the jump button, the following c# script executes: void Jump(){ if(Jumping) return; if(Time.realtimeSinceStartup-LastJump>0.4f){ Anim.SetBool("Jumping",true); Body.AddForce(new Vector2(0,350)); Jumping = true; } } As you can see, no jump is allowed if there is another in progress, and there must be a 0.4 seconds time span between jumps. Jumping is set to false when the jump animation ends. Since I'm applying constant force on each jump, I'm expecting all the jumps to reach the same height, but that's not what I'm getting. The jumping object sometimes only reaches about 75% of the expected height, and about 1 out of every 100 times doesn't even leave the ground. So why is this happening?... and how can I make my object always jump at the same height by applying the same force?

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>