|
Hello everyone, I want an object (let's call it Q) to rotate along its Y in exact sync with the camera. I set up this simple script:
and put it on Q and everything works fine until we hit about Y=230, when Q stops rotating (its value for Y peaks around 230 and starts to diminish, it doesn't go a full 360). Any ideas why Q doesn't keep going until 360? It's a basic sphere object, if that helps. Thanks for taking a look at this.
(comments are locked)
|
|
Transform.rotation is a quaternion, not an Euler-angle triple (this seems to trip people up quite often). What are you printing out exactly? If you're seeing values like 230, it must be something other than rotation.y, I would imagine. I'm not sure what Unity does behind the scenes when you assign a value to the y element of the rotation in UnityScript. It may assign the new y (or whatever) value, keep the values of the other elements, and then renormalize. In any case though, assigning the value of the y element of one quaternion to the y element of another is unlikely to produce the desired results, at least not in the general case. If the camera can be arbitrarily oriented but you want the object to remain upright (while still looking basically 'in the same direction' that the camera is looking), one solution would be to project the camera's forward vector onto the ground plane (which just involves zeroing the y element), and then use Quaternion.LookRotation() to orient the object accordingly. The only time this will fail is when the camera is looking more or less straight up or down (as it should). Thanks for pointing out the quaternion / euler angle difference, that put me on the right track. I ended up changing "transform.rotation.y" to "transform.eulerAngles.y" and it ended up working exactly as I wanted it.
Sep 21 '10 at 07:26 PM
Graham
(comments are locked)
|
