Question by
TheSaviour · Jul 12, 2016 at 07:13 PM ·
transformquaternionangleeulerangles
Change angle of a moving object but maintain direction of movement?
I have a game object that moves upwards infinitely. I used this line of code to achieve this:
rigidBody.MovePosition(transform.position + transform.up * Time.deltaTime*speed);
But then, I added this line of code to change the angle of the game object by 20 degrees about the z-axis:
rigidBody.rotation = Quaternion.Euler(0, 0, 20);
Although the game object was successfully rotated, the it no longer moves upwards. Now it moves towards the new direction it's facing.
Is there a way I can change it angle of the object such that it maintains its direction?
Comment