x


Quaternions, Eulers, and SmoothDampAngle

Hello everyone, glad to be on board here. Here's the issue: I have a cylinder that I need to move from a starting position/rotation to a new position/rotation over time. I've done this kind of thing in the past, but this time I've decided to take advantage of Unity's built in functionality. However, I'm new to Unity so I'm having trouble wrapping my head around the whole Quaternion/Euler thing. I've tried to start off just working with the rotation, and here's what I have so far:

private GameObject myCylinder; // this gets initalized in Start()
private Transform endCylinderTransform; // this holds the angle I want to rotate to
void SetupCylinderInfo()
{
     // this sets up the cylinders starting rotation
     Vector3 startingRotation = new Vector3(90.0f, 0.0f, 0.0f);
     myCylinder.transform.rotation = Quaternion.Euler(startingRotation);
     // I want the cylinder to rotate along the x-axis from 90 to 270 degrees
     endCylinderTransform = (Transform)Instantiate(myCylinder.transform);
     Vector3 endCylinderRot = new Vector3(270.0f, 0.0f, 0.0f);
     endCylinderTransform.rotation = Quaternion.Euler(endCylinderRot);
}

Below is the function where I try to do the rotation

float xVel = 0.0f;
void FixedUpdate()
{
     // get the angle using SmoothDampAngle.  I want to rotate it over 1 second
     float xAngle = Mathf.SmoothDampAngle(myCylinder.transform.eulerAngles.x,
                    endCylinderTransform.eulerAngles.x, ref xVel, 1f);
     Vector3 newRot = new Vector3(xAngle, 0.0f, 0.0f);
     myCylinder.transform.rotation = Quaternion.Euler(newRot);
}

Well, needless to say this isn't working. It rotates the cylinder a tiny bit but once it reaches it's end it bounces back and forth (probably because I'm not checking for the clamp). Can anyone tell me what exactly I'm doing wrong? I hope that once I get this sorted out I'll be able to deal with the translation in a similar way but first things first.

Thank you. If you need any other info please let me know. -Mo

more ▼

asked Dec 14 '10 at 11:04 PM

MoProductions gravatar image

MoProductions
51 12 13 17

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x439
x286
x134
x34

asked: Dec 14 '10 at 11:04 PM

Seen: 1231 times

Last Updated: Dec 14 '10 at 11:04 PM