x


How to, restrict Quaternion.Slerp to the Y axis?

Hello fellow uniteres!

I have a third person game where the camera is free to rotate around when the player is not moving. And when the player is moving the players Y axis lines with the cameras Y axis, but when doing so the player "snaps" to the cameras Y axis.

I want to make this smooth and therefor considering using Quaternion.Slerp, but the problem using Quaternion.Slerp is that it is "Slerping" all axis X, Y, Z, but as said I only want to "Slerp" the Y axis. Is this possible(It most likely, but I do not know how to) I have tried Mathf.Clamp, but that causes "shaky" movements and slow fall through the floor.

The current code I use for the rotation right now is this(small sample only):

  var GameCam : Transform; //Camera goes here.

    if(Input.GetAxisRaw("Vertical") > 0.1 && !Input.GetAxisRaw("Horizontal"))
    {
    transform.eulerAngles.y = GameCam.eulerAngles.y; // This is used for the rotation
    transform.Translate(0,0,Input.GetAxisRaw("Vertical")/20);//Movement no need to look at that.
    }

So can you please tell me a way to restricting "Slerping" to the Y axis only. I will be greatfull!

more ▼

asked Jun 08 '11 at 09:01 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

Can you post your current Slerp code?

Jun 08 '11 at 09:30 PM Chris D

I do not have any Slerp specific code since I could not for the life of me restrict it to the Y axis only so I sticked to the code in the updated post.

Jun 08 '11 at 09:52 PM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

yourRotationQuaternion = Quaternion.Slerp(to, from, time);

yourRotationQuaternion = Quaternion.Euler(new Vector3(0f, yourRotationQuaternion.eulerAngles.y, 0f));

done like dinner

more ▼

answered Jun 08 '11 at 09:57 PM

testure gravatar image

testure
4.2k 20 25 48

Thank you. tried messing with it, but importunately the player only turns/rotates 0.8 degrees each direction and nothing more and then the player is kinda "clamped" there and can not rotate further.

Jun 08 '11 at 10:14 PM OrangeLightning

You corrected Anxo, but you made the same mistake. yourRotationQuaternion.y is not an euler value so putting it into Quaternion.Euler is a mistake

Jun 09 '11 at 01:50 AM Peter G

Ah- yes. I've edited my post to clarify.

Just more proof that we need intellisense here too :)

Jun 09 '11 at 02:29 AM testure
(comments are locked)
10|3000 characters needed characters left

transform.rotation.y = Quaternion.Slerp(bla bla bla).y;

more ▼

answered Jun 08 '11 at 10:29 PM

Anxowtf gravatar image

Anxowtf
1.6k 22 27 37

yeah, but Y is not what you're thinking it is- he's talking about restricting to the Y euler angle, this would give you the Y quaternion component, which is not the same thing:

http://unity3d.com/support/documentation/ScriptReference/Quaternion.html

Jun 08 '11 at 10:45 PM testure

oh I guess I tried to answer the title without reading the question.

Jun 09 '11 at 11:52 AM Anxowtf
(comments are locked)
10|3000 characters needed characters left

After the Quaternion.Slerp statment

transform.localEulerAngles = Vector3(0, transform.localEulerAngles.y, 0);

more ▼

answered Jun 09 '11 at 05:21 AM

flim gravatar image

flim
16 2 3 6

(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:

x2165
x439
x207

asked: Jun 08 '11 at 09:01 PM

Seen: 2000 times

Last Updated: Jun 09 '11 at 11:52 AM