- Home /
I use this code to jump, but it's just teleporting my player upwards. It works totally perfect in an other project.
public class Jump : MonoBehaviour {
public float JumpForce = 150f;
Rigidbody2D rb;
void Start () {
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate () {
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector2.up * JumpForce * Time.deltaTime);
}
}
}
Answer by hameed-ullah-jan · Oct 30, 2018 at 04:33 PM
Try this thing hope it will work:
if(Input.GetKeyDown(KeyCode.Space) && isGrounded) {
rb.AddForce(jump * jumpForce, ForceMode.Impulse); isGrounded = false; }
check your gravity, are you sure that gravity is on?
Answer by The_Phantom16 · Oct 30, 2018 at 10:47 PM
Um...let me see if I can try to help.
1) Created a small project for this. Here is my setup in the editor (just in case the issue is not in the code):
2) Programming wise, I just copied and pasted your code. Got rid of the Time.deltatime because you already have the jump code in the FixedUpdate() (also it causes the object have really really tiny jumps):
3) I ran the project, pressed the space bar and it works for me.
Hope this helps you out! :D
Thank you, it not helps a lot becouse I alredy knew it, but I'll remove the Time.deltaTime.