- Home /
Question by
icybergenome · Aug 05, 2017 at 04:34 PM ·
rotationmotioncirculartransformation
How to create a circular motion using circular equation along with rotation of object?
Hi,
Most of the content that I found related to circular motion address only position of the object and the rotation of the object remain constant. Please refer to the attached pic for better demonstration.
Basically what I want is when an object is in a circular motion its also rotating and positioning in a same angel. Instead it should be:
As per code I tried so far:
speed = (Mathf.PI * 2) / timeToCompleteCircle;
float x;
float y;
switch (direction) {
case "left":
if (currentAngle >= 2 * Mathf.PI)
currentAngle = 0;
x = radius * Mathf.Cos (currentAngle);
y = radius * Mathf.Sin (currentAngle);
transform.localPosition = new Vector3 (x, y, 0);
rotationAngles = Quaternion.EulerAngles (new Vector3 (0, 0, currentAngle));
initialRotation = transform.localRotation;
transform.localRotation = Quaternion.Lerp (initialRotation, rotationAngles, smooth);
currentAngle += Time.deltaTime * speed;
break;
orig.jpg
(44.7 kB)
should.jpg
(42.0 kB)
Comment