|
I am using the following code to setup my rotations: As you can see I'm using 'Quaternion.LookRotation( direction.normalized )' to calculate the rotation towards the new target, but this only works on 'transform.forward' and my vehicle is moving on the x axis (transform.right) instead of the z axis, which is forward. That's why i do 'newRotation.eulerAngles.y - 90' in the angle calculation. I would rather not do that, and I also don't want to child the vehicle to a parent which faces forward, so I was wondering if there is any alternative to Quaternion.LookRotation() that i can use, which doesn't force the rotation to the z axis? Thanks for your time guys! Any help is greatly appreciated :) Stephane
(comments are locked)
|
|
Found the solution, here is an alternative to using Quaternion.LookRotation(): The Mathf.Atan2 function return an angle from 2 numbers (* Mathf.Rad2Deg is necessary to convert the angle to degrees), which is all I needed! Then I just create a smooth rotation from my vehicle's current y rotation to the new angle, and apply the results to "rigidbody.MoveRotation()". Only thing I had to do for it to work correctly was to use '-turnAngle' instead of 'turnAngle' for the rotation to happen in the correct direction. That's it! Maybe this will be helpful to others :) Stephane
(comments are locked)
|
|
There's an overload for LookRotation that allows you to specify the 'Up' vector. Just change that line to and you should be sorted. Thanks for the suggestion Kieren, but I've already tried that a few times and it doesn't work, since I need my rotation to happen on the up vector to turn the vehicle left/right, and if I change it to transform.right, it rotates the vehicle on the X axis and still tries to point the transform.forward axis towards the next target. Stephane
May 01 '12 at 06:36 PM
ronronmx
(comments are locked)
|
