I’m pretty new to Unity, so I assume I jipped something up. I’m trying to use the AddForce function to simulate my object jumping. What am I doing wrong?
void jump () {
if (Input.GetKey (KeyCode.W)) {
rb.AddForce(Vector2.up * thrust, ForceMode2D.Force);
}
}
Snippet looks fine. When are you calling jump()?
It’s being called in the Update function, right after my movement function that controls left and right movement.
abnu
June 12, 2015, 6:21am
4
What mass does your rigidbody have and what’s the value of thrust?
This leads me to believe your thrust is too low. Yoy should also be doing physics in fixed update
I fiddled around with it, editing to parts of movement code videos I was watching.
//Jump Control
void jump () {
if (Input.GetKeyDown(KeyCode.W)) {
rb2D.AddForce(transform.up * jumpHeight, ForceMode2D.Impulse);
Debug.Log("No.");
}
}