Doubts with rotation, deltatime and Clamp
Hello everybody.
I am a designer that has recently started to learn scripting with the Unity Scripting Tutorials and I have this problem that gets me totally confused.
I'm trying to do that the canon of a static tank, rotate up and down no more that 90 degrees. However if I use EulerAngles, I get the rotation from 0 to 360 and the Inspector show me between 0 to 180 and from -180 to 0 (and that doesn't help me for understanding whats is going on). Secondly, if I use Time.deltaTime, the Euler Angles goes to a ridiculous value. Finally, if I try to clamp the values the rotation gets crazy.
Below of this text you can see what I am trying to do and 2 pictures for visual help. by the way I haven't wrote the Clamp because the result is totally a mess when I try it.
I couldn't appreciate enough if someone could explain me what I am doing or understanding wrong.
Thank you so much.
Cheers ^w^
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class autoRot : MonoBehaviour {
private GameObject autoRotCanon;
public Vector3 canonAngles;
// Use this for initialization
void Start () {
autoRotCanon = GameObject.Find("canon_tank01");
canonAngles = autoRotCanon.GetComponent<Transform>().eulerAngles;
Debug.Log(canonAngles);
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.LeftArrow))
{
canonAngles = new Vector3 ((-(canonAngles.x + 10) * Time.deltaTime), 0.0f, 0.0f);
autoRotCanon.transform.Rotate(canonAngles);
}
}
}
Unity doesn't store rotations as 0-360. There's a whole complicated conversion process. You can search around for things like "unity set eulerangles." $$anonymous$$y explanation, etc... is in a chapter at http://www.taxesforcatses.com/vectorW/ch4Rotation.pdf if you have the patience.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110007im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object don't rotate correctly 1 Answer
AI targeting player in complete wrong direction 1 Answer
Ambient Emitter inside a BoxCollider - Rotation not recognized 0 Answers
Trying to turn my player model 0 Answers
Rotating object over time 0 Answers