- Home /
How to rotate an object to a specific angle with angularVelocity?
I use velocity to move an object to a certain point (the same position as gameObject target):
Vector3 desiredLocation = target.transform.position; Vector3 currentLocation = myGameObject.transform.position; Vector3 vel = (desiredLocation - currentLocation) * Time.fixedDeltaTime * speed; myGameObject.GetComponent ().velocity = vel;(That code already works perfectly fine).
But how can I do something like this but with rotation?
· "transform.rotate" isn't what I want because it adds a CONSTANT rotation. I want it to rotate its angle towards the angle I told it to, until it's there. If the target rotation and the myGameObject rotation are the same, it should not rotate at all.
· Directly changing "transform.rotation" isn't what I want because that would be INSTANTANEOUS.
· That's why I want to do it with angularVelocity. But I guess I need to know about Quaternions for that? I don't fully understand Quaternions yet.
This is what I tried to do:
I use angularVelocity to rotate an object to a certain angle (the same angle as gameObject target):
Vector3 desiredAngle = target.transform.rotation; Vector3 currentAngle = myGameObject.transform.rotation; Vector3 angVel = (desiredAngle - currentAngle) * Time.fixedDeltaTime * speed; myGameObject.GetComponent ().angularVelocity = angVel;It doesn't work. The cube is crazy. I have no idea what I'm doing. Please help.
Comment