- Home /
Why does GetComponent().velocity.y not equal the second value of GetComponent().velocity?,Why does GetComponent().velocity output (0.0,0.0) but GetComponent().velocity.y outputs a non-zero number?
I was trying to make a double jump system for a platformer--my original code allowed you to basically infini-jump, so I was trying to keep it to two jumps total. But I had trouble determining when the player is at rest, because I was using GetComponent<Rigidbody2D>().velocity.y to determine "rest"; however when using Debug.Log I noticed that GetComponent<Rigidbody2D>().velocity.y wasn't ever 0.0, even when GetComponent<Rigidbody2D>().velocity was outputting (0.0,0.0).
I got around it by doing an if statement with GetComponent<Rigidbody2D>().velocity == new Vector2(0.0f,0.0f) but I'd love an explanation as to why velocity.y doesn't give the expected y value of velocity. ,I was trying to make a double jump system for a platformer--my original code allowed you to basically infini-jump, so I was trying to keep it to two jumps total. But I had trouble determining when the player is at rest, because I was using GetComponent<Rigidbody2D>().velocity.y to determine "rest"; however when using Debug.Log I noticed that GetComponent<Rigidbody2D>().velocity.y wasn't ever 0.0, even when GetComponent<Rigidbody2D>().velocity was outputting (0.0,0.0).
I got around it by doing an if statement with GetComponent<Rigidbody2D>().velocity == new Vector2(0.0f,0.0f) but I'd love an explanation as to why velocity.y doesn't give the expected y value of velocity.
Your answer
Follow this Question
Related Questions
Inconsistent jump height 1 Answer
Inconsistent jump height 1 Answer
Mario Styled Jumping 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers