- Home /
Question by
Qualien · Jun 04, 2020 at 08:41 PM ·
rigidbody2dvelocityaxisaxesnormalized
Rigidbody2D Normalizing only one axes
So in the game, I am working on, I need the velocity of the player on the Y axis to be constant (only on the Y axis not on X axis). So I've made this basic code which should be only making the Y axis constant but for some reason the X axis also gets constant. In the end that's a problem, as it messes with my movement script.
public float constantSpeed; private Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { Vector2 vel = new Vector2(transform.position.x, constantSpeed); vel = vel.y * (rb.velocity.normalized); rb.velocity = vel; }
Comment