Rotating to a certain degree and stopping?
I'm a bit new to unity and c# and I can't manage to stop a rotation at a certain degree.
using UnityEngine;
using System.Collections;
public class RotateBase : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate (Vector3.up * 0.5f);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.down * 0.5f);
if (transform.rotation.y > 45)
transform.Rotate (Vector3.up * 0.0f);
}
}
When I press the left and right arrows it rotates all the ways around. I tried stopping the rotation when it hit 45 degrees but I have no clue how to do it. All I know at the moment is basic C# code so if someone can show me how to make the rotation halt at 45 degrees when I'm pressing the right arrow and 315 degrees when I press the left arrow I would be very greatful. Try to keep it simple if you can please.
Answer by Konomira · Oct 11, 2015 at 03:57 PM
If I recall correctly, Unity uses quaternions as opposed to degrees. use Transform.eulerAngles to work in degrees.
http://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html
Answer by coreykadd · Oct 14, 2015 at 07:44 PM
Ya, sorry but I still don't know how to stop the rotation at a certain degree.
Your answer
Follow this Question
Related Questions
Object orientation remains the same while rotating object 1 Answer
Rotating camera not working? 0 Answers
how to get object rotation? 1 Answer