- Home /
Object not rotating when the associated trigger is triggered
Hi guys,
I have a sphere collider that works just fine as a trigger, with the following code being executed:
var lid : GameObject; var ring : GameObject; var toiletController : GameObject;
function Update () { }
function OnTriggerEnter(col : Collider) { OpenLid(); }
function OpenLid() { if (lid.transform.rotation.z < 90) lid.transform.Rotate (0, 0, Time.deltaTime * 10); Debug.Log("Player next to toilet, add code to open the lid"); }
All of the toilet bowl's variables are linked in the game world to the appropriate lids, rings, and control panels. However, while triggering the toilet bowl's sphere trigger causes the debug log to get printed, the associated toilet lid isn't rotating. The toilet lid should go from 0 degrees on the z axis to 90 degrees in a smooth way, instead of staying static while the debug log gets printed. Where did I get my rotation code wrong?
MachCUBED
Answer by kayy · Dec 23, 2011 at 10:19 PM
transform.rotation.z is just the z component of the quaternion - mathematically pretty abstract thing. Use transform.rotation.eulerAngles.z and it should do.
I changed my code to look like this:
function OpenLid()
{
if (lid.transform.rotation.eulerAngles.z < 90)
lid.transform.Rotate (0, 0, Time.deltaTime * 10);
Debug.Log("Player next to toilet, add code to open the lid");
}
It still didn't work, so I changed it to look like this:
function OpenLid()
{
if (lid.transform.eulerAngles.z < 90)
lid.transform.Rotate (0, 0, Time.deltaTime * 10);
Debug.Log("Player next to toilet, add code to open the lid");
}
And it still didn't work. Bummer.