3drotationunity-game-enginemonodevelopboo

Object rotation script failing(Unity3d, Boo)


I'm trying to create a security camera that pans back and forth in a game I've been building. For some reason it just keeps rotating and never reverses direction. I tried it with transform.eulerAngles.y as well with no success and couldn't find anything with several lengthy Google searches. Any assistance on this matter would be greatly appreciated :) Thank you in advance

import UnityEngine

class RotationScript (MonoBehaviour):

minRotation = 186
maxRotation = 263

def Start():
transform.Rotate(Vector3.left * Time.deltaTime * 10)
def Update():
if self.transform.rotation.y <= minRotation:
transform.Rotate(Vector3.right * Time.deltaTime * 10)
if self.transform.rotation.y >= maxRotation:
transform.Rotate(Vector3.left * Time.deltaTime * 10)

Solution

  • Well, first off, transform.rotation.y isn't in euler angles (ie 0-360 degrees), it uses quaternions. You were correct the first time, when using transform.eulerAngles , but there are one or two things you should check first.

    For starters stick the line: Debug.Log(transform.eulerAngles.y) above your if clauses. You may find that you're not actually rotating on the Y axis (unity is weird about this sort of thing, so that's quite often the case). Or you may find that you're rotating at negative degrees (although in my experience this doesn't occur, even though giving an object a negative angle will work just fine).

    You could also try rotation.localEulerAngles.y instead, which may work better depending on the parenting and rotation of your camera object.