- Home /
How do I stop an object from jumping VERY high at first?
Hi guys! So I have a problem with my player GameObject. Every time I do my "Jump" command at the start of the game, it manages to jump ridiculously high. But after that, it starts jumping normally again. Is there some way I can prevent that from happening? Thank you in advance. Oh, and here's my "Jump" command script:
var Jumped = false;
var JumpHeight = 7500f;
function Update ()
{
if(Input.GetKey(KeyCode.Space) && !Jumped)
{
Jumped = true;
rigidbody.AddForce(Vector3.up * JumpHeight * Time.deltaTime);
}
}
And here is what I use to prevent jump spamming, its connected with the code above.
function OnTriggerStay ()
{
Jumped = false;
}
What I've also noticed is that upon starting, the GameObject has a Y coords of 0. But, after the jump, it becomes around -0.00002
Answer by slek120 · Apr 06, 2014 at 08:32 AM
You don't need to multiply by Time.deltaTime, so change JumpHeight to 125 and remove Time.deltaTime. If you really care about the -0.00002, you can change the rigidbody collision detection to continuous but this isn't necessary unless your rigidbody moves really really fast.
Works like a charm! Thank you so much! Hey, can you check if you know about my other question about my player object falling slowly? Thanks in advance!
Your answer
Follow this Question
Related Questions
Jump off the edge of the object 1 Answer
Making a player jump, getting random results 2 Answers
jump on collision weird behaviour 2 Answers
What's wrong with this script? 4 Answers