I have a character who walks to random points in my room in Unity. The problem is he always faces one direction, I want to write in C# a piece of code that will get the direction the character is currently facing and the position of the target, then works out the angle between them to turn the character that amount. I have tried the LookAt function but that makes the character walk in an arc shape towards the target which looks very unnatural as it constantly looks at the target.
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
|
|
|||||
|
|
The LookAt function does this for you. You may be using it improperly, or something is wrong with your steering if you're having problems with this. You can try it this way too:
Now you can either snap towards that rotation, or you can do it slowly over time. (slowly over time means all this code needs to go into the update function)
For 2D another alternate method would be Atan2:
|
|||||
|
