hey, i’ pretty new to scripting and i have some basic problems.
actually i want to have a cylinder to be rotated in its center by the arrow keys (left and right). whenever no key is pushed it should be roated back to the origin, depending on which way is shorter, either left or right.
thus i made a script for the input of the keys and attached it to the object:
using UnityEngine;
using System.Collections;
public class rotate : MonoBehaviour {
void Update() {
if (Input.GetKey(“left”)) {
transform.Rotate(Vector3.left * Time.deltaTime * 400);
}
if (Input.GetKey(“right”)) {
transform.Rotate(Vector3.right * Time.deltaTime * 400);
}
}
}
this is how i imagined how it would work:
- save the origin (?)
- check if no keys are pushed
- check whether rotating back the left way to the origin or the right way is shorter.
- stop when the original position is reached.
would be nice if you could get me some hints how to deal with this ![]()