For the last few days I’ve been trying to have a rigidbody2d rotate while keeping its current velocity only changing where the velocity is directed. After some research, this is what I’ve come up with:
var v:float;
v = rigidbody2D.velocity.magnitude;
var cos=Mathf.Cos(gameObject.rigidbody2D.rotation);
var sin=Mathf.Sin(gameObject.rigidbody2D.rotation);
var unitvector : Vector2;
unitvector = Vector2(cos,sin);
unitvector=unitvector.normalized;
var x : float;
var y : float;
x=unitvector.x;
y=unitvector.y;
gameObject.rigidbody2D.velocity=Vector2(x*v,y*v);
However, this only makes the object stand still in the air slighty wiggling back and forth when I press the key. What’s wrong with my solution and how can I fix it?