I’ve looked at a lot of questions that were very similar to this but I’m still confused on how to handle rotations in Unity.
Here’s my problem:
I have an Object - obj
and it’s transform is:
Position: 0,0,0
Rotation: 90,180,0
Scale: 0,0,0
now I want to change the transform to:
Position: 0,0,0
Rotation: 180,180,0
Scale: 0,0,0
it’s easy to run the game grab the handle and pull it around.
but how do I do this in code. These Quaternion are totally throwing me off.
I would love to see something to change it using a LERP and an instance change.
Thanks.
Addendum:
I wrote a small script to test what I want to do and so that others can better understand what I’m trying to do as well.
Here’s the script.
public class RotationLerpTest : MonoBehaviour
{
public Quaternion rotation;
public float speed = 0.1f;
// Use this for initialization
void Start ()
{
rotation = transform.rotation;
}
// Update is called once per frame
void Update ()
{
transform.rotation = Quaternion.Lerp (transform.rotation, rotation, Time.deltaTime * speed);
}
void OnMouseUpAsButton ()
{
rotation.z += 90*Mathf.Deg2Rad;
}
}
It almost works perfectly except the rotation is some like 117 deg instead of 90. I know this has something to do with Quaternions but i can’t figure it out.
I've seen this example. But, it doesn't seem like I can create a transform, so I don't see how to implement this. In the example they have a transform already, I don't.
– prak