- Home /
Rotate gameobject on Y axis
Hey all. I am trying to rotate a gameobject (in this case, a door) by 90 degrees in its Y axis when the player enter the sphere collider around the door, basically opening the door.
using UnityEngine;
using System.Collections;
public class DoorOpen : MonoBehaviour
{
private GameObject player;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject == player)
{
transform.Rotate.y(0,90,0);
}
}
}
Here I tried transform.Rotate.y
but getting an error. I can't seem to find the correct way to format the code to simply rotate. On a side note, not entirely necessary, but is there also a way to slow the rotation down, instead of making it happen in a single frame, to better simulate the opening of a door?
Rotate() is used like this:
transform.Rotate(0,90,0);
Note this causes the whole rotation in a single frame.
Try making an animation for the door ins$$anonymous$$d
I did, but I dont really know how to use the animations, and I am working on a 5 day deadline, with a lot of work left to do. So I am trying to stick with what I know.
Answer by gdubrocks · May 11, 2014 at 06:23 AM
You can make the movement occur over multiple frames by using Vector3.lerp() or Vector3.slerp, but as previously stated an animation is probably the better solution.
https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Slerp.html
Your answer
Follow this Question
Related Questions
C# Rotate GameObject at Other Point other than Center 3 Answers
Rotate Object 180º OnClick 3 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
C# Rotate More than Two GameObjects 1 Answer