Character jumping too fast
Hi, I'm creating a 2.5D Platformer to finish my character controller which uses a rigidbody because most of the obstacles work adding force to the player.
I solved all the movement part in this post (http://forum.unity3d.com/threads/help-with-my-character-controller.429769/#post-2778885) and created a bool to checks if the player is grounded watching some tutorials.
The problem is that now that I tried to make the character jump with this code:
public float jumpForce;
void Start ()
{
myRb = GetComponent <Rigidbody>();
void Fixed Update ()
{
if (Input.GetButtonDown ("Jump"))
{
Jump ();
}
}
void Jump ()
{
if (isGrounded)
{
myRb.AddForce (Vector3.up * jumpForce);
}
}
And when I press the button the player moves up extremely fast. Scaling the value just makes the player jump less high (which I don't want, since I need the player to be able to jump 2 units). Is there any way to make the player jump to that height less quick?
PD: There is some drag value to the rigidbody, so that it stops when i stop pressing A or D.
Answer by AurimasBlazulionis · Sep 08, 2016 at 09:33 AM
You can set a variable like jumpStart
to`Time.time` when you press a button and the player is grounded. Then have a value like forceTime
which stores the time for applying force. Now, in FixedUpdate do a check if (Time.fixedTime - jumpStart < forceTime)
and if it is true, add smaller force. This will add force continiously so it will be able to jump slower, but fall faster.
Alternatively, you can lower gravity in physics tab, or increase drag of rigidbody to unrealistic levels (but then you will need to add more force I guess).
Thanks, I lowered the gravity and played a little bit with the drag and now it works fine =D.