- Home /
Question by
waywardchicken · Dec 12, 2012 at 07:21 AM ·
animationrotate
Need a "square tire" script. HELP!
I'm trying to make a block rotate in the specific direction of a key press. I.E. if W is pressed the block rolls forward as if it were a square tire, A would make it roll to the left, D to right, S backwards.
Cannot for the life of me figure it out.
Link for reference.
Comment
Best Answer
Answer by ZenithCode · Dec 12, 2012 at 10:13 AM
This should answer your query!
using UnityEngine;
public class RotateCube : MonoBehaviour
{
public GameObject CubeToRotate;
void Update()
{
if (Input.GetKeyUp(KeyCode.W))
{
CubeToRotate.transform.RotateAround(CubeToRotate.transform.position, CubeToRotate.transform.forward,90f);
}
if (Input.GetKeyUp(KeyCode.S))
{
CubeToRotate.transform.RotateAround(CubeToRotate.transform.position, -CubeToRotate.transform.forward, 90f);
}
if (Input.GetKeyUp(KeyCode.A))
{
CubeToRotate.transform.RotateAround(CubeToRotate.transform.position, CubeToRotate.transform.right, 90f);
}
if (Input.GetKeyUp(KeyCode.D))
{
CubeToRotate.transform.RotateAround(CubeToRotate.transform.position, -CubeToRotate.transform.right, 90f);
}
}
}