I would like to have my player run into a trigger or something of the sort and have the player turn 90 degrees and have the object turn 90 degrees. How would I go about doing this?
I think its called setTransform but I'm not exactly sure.
Here is an example of what exactly should happen:
player is facing you and he is running forward and getting closer to you.
He hits a trigger or something invisible
That makes him turn 90 degrees and the object he is walking on turns 90 degrees also.
I think this is pretty easy to do its just I'm pretty new to Unity since I switched over from Torque.
To rotate an object 90 degrees immediately when it enters a trigger of a certain type, place this on the player:
function OnTriggerEnter(otherCollider : Collider) {
// rotate 90 degrees around the object's local Y axis:
transform.Rotate(0,90,0);
}
This will cause any trigger to rotate the player. You might want to have other triggers in your scene which perform other functions. In this case, create a new tag called "RotationTrigger", and tag the triggers that you want to have this effect with this new tag. Then you can check for the tag before determining what should happen to the player.
For example:
function OnTriggerEnter(otherCollider : Collider) {
if (otherCollider.tag == "RotationTrigger") {
transform.Rotate(0,90,0);
}
}
You could also extend this further to rotate left, or right, or complete the game depending on the trigger's tag:
function OnTriggerEnter(otherCollider : Collider) {
switch (otherCollider.tag) {
case "RotateLeft": transform.Rotate(0,90,0); break;
case "RotateRight": transform.Rotate(0,-90,0); break;
case "Finish": FinishGame(); break;
}
}