I want to take a vector and apply a rotation to it. Specifically, I want to take the velocity of an object, and directly rotate it. The idea being that rather than an object having to apply force to change direction, it would just have to turn, and its momentum would follow.
What’s the easiest way of going about this?
You can multiple a quaternion and a vector to rotate the vector. You just need a quaternion describing your rotation, so maybe:
or
Although I think there are other ways of accomplishing sharp turning that are more flexible and tunable. What sort of feel are you looking for?
How exactly would that look in code? Something like this?:
var rotation = Quaternion.Euler(0, 30, 0);
rigidbody.velocity = rigidbody.velocity * rotation
The specific scenario is I have an aircraft which moves in a fairly physically unrealistic manner. If the player stops accelerating, then it should slowly decelerate, but continue flying in a straight direction if they turn. It seems to me that the easiest way would be to turn the velocity of the aircraft while the object itself is turning.
Ultimately the problem I’m having is that I don’t want the aircraft to slide around turns. I also want the aircraft to maintain forward momentum when it turns, even if it’s no longer accelerating.
Any suggestions for a better way of handling this?