x


Quaternion.Slerp and Quaternion.Euler problem

Greetings.

I am making a script that uses Quaternion.Slerp command. It works, but I need to constrain the x and z-axis rotation so that only y-axis rotates. I've tried this with Quaternion.Euler but it didn't work. Here is a snippet of my script.

private var speed = 5;
    var newRotation = Quaternion.LookRotation(targetObj.position - head.transform.position);

    head.transform.rotation = Quaternion.Slerp(head.transform.rotation, Quaternion.Euler(0,newRotation.y,0), Time.deltaTime * speed);

Thank you in advance.

more ▼

asked May 06 '12 at 11:06 AM

Yonlop gravatar image

Yonlop
0 3 3 3

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

1 answer: sort voted first

Okay nevermind. I got it. Just specified the x and z initially and it works.

var newRotation = Quaternion.LookRotation(targetObj.position - head.transform.position);
newRotation.x = 0;
newRotation.z = 0;

    head.transform.rotation = Quaternion.Slerp(head.transform.rotation, newRotation, Time.deltaTime * speed);

I'm just wondering if there is an overall implication to how the object react to other scripts, but it looks okay for now.

more ▼

answered May 06 '12 at 11:47 AM

Yonlop gravatar image

Yonlop
0 3 3 3

(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x2241
x458
x124
x89
x49

asked: May 06 '12 at 11:06 AM

Seen: 746 times

Last Updated: May 06 '12 at 11:47 AM