Search Unity

is transform rotation is bugged?

Discussion in 'Scripting' started by vargata, Jan 19, 2014.

  1. vargata

    vargata

    Joined:
    Nov 26, 2013
    Posts:
    39
    Hi all

    I have a little problem with creating a spaceship control. Not because I dont know how to do it, but because things doesn't work as they supposed to work.
    here are 2 little videos: http://www.youtube.com/watch?v=qAKZgoTpcsM and http://www.youtube.com/watch?v=8bAQzoywEP8
    the first is with rotating around world Y. it's a lot better until I pitch up, the second one shows the intended working mechanism but on that at 0:25 you can see that if I start circling with the mouse, the object start to rotate around Z, and thats what I don't know where it comes from.
    here the code is: http://answers.unity3d.com/questions/619536/pitch-rotation.html

    As you can see I was experiencing with a few methods, the transform.Rotate was the best (second video) but still far from perfect.
     
    Last edited: Jan 19, 2014
  2. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    Accumulated x- and y-axis rotations like that will create rotations on the z-axis as well eventually. There will also be accumulated floating point error when you are applying small relative rotations every frame.

    If transform.Rotate() works basically how you want, then use that. Correct the error with Quaternion.FromToRotation(transform.up, intendedRollAmount). Or use Quaternion.Slerp to make it smoother, but if you are correctly it constantly you will never get huge amounts of error piling up so both methods should end up looking similar.

    I would also use Quaternion.AngleAxis to create the localRotation and assign it to transform over using transform.Rotate. It gives you a bit more direct control over exactly what's happening.