- Home /
Stopping rotation at 90° and -90°/270°.
I have an Transform that i am rotating backwards through touch commands on android. The rotation itself works fine. What I want to happen though is when it reaches 270 / -90 that it cannot rotate anymore and the same if it reaches 90 degrees the opposite direction. Upon reaching those points i want it to reset back to its zero degree rotation. Any help would be greatly appreciated. Thanks in advanced.
My code: [code]using UnityEngine; using System.Collections;
public class Pivot : MonoBehaviour {
public float speed = 10.0f;
public Vector2 touchDeltaPosition;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
touchDeltaPosition = Input.GetTouch(0).deltaPosition;
}
}
void LateUpdate () {
if(Input.touchCount > 0 && touchDeltaPosition.x <= 0) {
if(transform.rotation.z >= 270 || transform.rotation.z <= 90) {
transform.Rotate(0, 0, -speed );
}
else {
transform.Rotate(0, 0, 270);
}
}
}
}[/code]
you are also not checking euler angles in your if stmt, which is going to give you funky results.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotating Joystick on Touch 0 Answers
Touch Hold for Power 1 Answer
Why the player is not rotating and moving at the same time ? 0 Answers
Timer Freeze Problem 1 Answer