- Home /
Jump code breaks my character
2D Movement code: float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed; rb.velocity = new Vector2(horizontalMovement, rb.velocity.y);
But when i insert jump code my character starts floating down and doesn't collide with other colliders
Here's the code: float jumpMovement = Input.GetAxis("Jump") * jumpForce; rb.velocity = new Vector2(rb.velocity.x, jumpMovement);
Answer by GamitusLabs · Oct 18, 2018 at 03:15 PM
Why not use Rigidbody.AddForce? It's basically made for things like jumping
How can i get it to work well? This doesn't work: if (Input.Get$$anonymous$$ey("Space")) { rb.AddForce = new Vector2(0, jumpForce)); }
Says cannot assign to addforce because it is method group or something
As TreyH says its a function that you pass your force and forcetype.
https://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html
rb.AddForce(transform.up * thrust);