- Home /
Making a jump with Rigidbody2D character
I'm trying out the newish Unity 2D features.
I'm trying to make a basic platformer. I've got left/right movement working with AddForce but I'm getting stuck on the jump. Here's what I have:
if (Input.GetKeyDown(KeyCode.Space) & grounded) {
jumping = true;
rigidbody2D.AddForce(jumpForce * Time.deltaTime);
}
The problem with using the AddForce method is that to get the character to jump I have to set an quite high value to the jumpForce vector, and when adding a big force the character "teleports" quite high quite fast: it's not a smooth jump.
How would you make a Rigidbody2D jump for a 2d platform game?
Answer by Esildorr · Apr 09, 2014 at 10:08 PM
In my game I changed its velocity:
var jumpForce : float = 10.0;
rigidbody2D.velocity = Vector2(0,jumpForce);
I've tried:
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) & grounded) {
print("the debug text displays");
jumping = true;
rigidbody2D.velocity = new Vector2(0, jumpForce);
}
No matter what value I give to jumpForce my character doesn't move at all.
Is there something I'm not getting? (Did you apply gravity manually?)
$$anonymous$$ake sure your mass on the ridgedbody is not to high, use gravity is checked. And you might have to play with the jumpForce variable. $$anonymous$$ake higher.
Your answer
Follow this Question
Related Questions
Rigidbody AddForce Up - different value. 1 Answer
rigidbody.Addforce the force doesnt apply? 1 Answer
Keep Horizontal Momentum after Jump 2 Answers
How do I make my character jump? 1 Answer