- Home /
Rotating a character's velocity?
I'm coming along quite well in this project of mine, but I can't seem to get the turning quite sharp enough. As it is, when the player directs movement in a new direction, the velocity gradually changes to that direction. It makes for some slightly slide-y controls. So I want to turn the direction of the velocity instead. The closest thing I've come up with so far is this:
rigidbody.velocity = Vector3.RotateTowards(rigidbody.velocity.normalized, desiredVelocity.normalized, Handling*Time.deltaTime, 1000)*rigidbody.velocity.magnitude;
And it works great on a flat plane, but my character is going to be walking on walls and riding bumpy surfaces as well. This particular function makes the character stop doing that, and almost makes it stop adhering to gravity.
If anybody has skill with Vector3's or Quaternions, this noob would be quite grateful for help! ^^;
Answer by james flowerdew · Sep 07, 2010 at 01:32 PM
What we do is grab the magnitude of the momentum/velocity then multiply it by a normalized vector representing forwards in the new chosen direction. this makes the objects turn without drag, skid or slow-down.
As a note hard setting the velocity of rigid bodies might make the physics look a little odd, but we also frequently like to rely less on applying forces (which can look a bit rubbery and unresponsive), and direct manipulation of velocity etc is "usually" fine.
Cheers,
James
Answer by StephanK · Jun 14, 2010 at 07:33 AM
Changing a rigidbodies velocity is most often not the best solution. I don't know what kind of game you are creating, so maybe this answer is completly useless.
Instead of changing the velocity directly you should apply forces to it. By balancing the strength of the forces and the drag of the rigidbody you should be able to get the wanted control feeling.
This is also expressed in the unity doco at some points. I have to whole heartedly agree with this. $$anonymous$$ost of the answers work in one direction or on a 2d design game but when the Go 3d orientation comes into play the developer can run into gimbal lock or velocity being applied in a direction that is opposite to the actual direction the GO is vectored or Quaterioned to. The developer will see the GO bouncing strangely or traveling in reflective directions ins$$anonymous$$d of continuing in the supposed direction.Changing a rigidbodies velocity is most often not the best solution
Answer by HolBol · Jul 26, 2010 at 11:11 AM
Just add a constant force too it instead, and limit the drag, and it'll do just what you want :).
Your answer
Follow this Question
Related Questions
Rotate vector around vector? 2 Answers
Rotate Towards doesnt work as expected 2 Answers
How to rotate a vector 1 Answer
Need very specific help with Quaternions 1 Answer
How to add 2 Quaternions. 2 Answers