Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed May 10, 2013 at 02:08 PM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by smirlianos · May 10, 2013 at 11:35 AM · rotationquaternionrotateslerpeuler

Quaternion.Slerp problem...

Hello!

I have this script that is supposed to turn the player smoothly on the direction that he walks. But the problem is that it turns immediatly, like the electrons of CERN!!!! What's wrong?


 #pragma strict
 var speed : float = 0.7;
 var playergraphic : GameObject;
 var RotSpeed : float;
 private var newRot = Quaternion.Euler(0,90,0);
 function Start () {
 
 }
 
 function Update () {
     var CurrentSpeed = Input.GetAxis("Horizontal") * speed;
     
     rigidbody.velocity = Vector3(CurrentSpeed,0,0);
     playergraphic.transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.time * RotSpeed);
     
     if(rigidbody.velocity.x > 0)
     {
         newRot = Quaternion.Euler(0,90,0);
         playergraphic.animation.CrossFade("Walk");
     }
     else if(rigidbody.velocity.x < 0)
     {
         newRot = Quaternion.Euler(0,270,0);
         playergraphic.animation.CrossFade("Walk");
     }
     else {
         playergraphic.animation.CrossFade("Idle");
     }
 }



The player has the main capsule collider as a parent object, and the graphicks are on a child object, that I want t turn. This is attached to the variable "playergraphic"

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by fafase · May 10, 2013 at 12:10 PM

Time.time is not what you want there.

Time.time is 1 after 1s meaning that after 1 sec your rotation will occur instantly.

You may want to use Time.deltaTime * rotSpeed instead. With rotSpeed being there to regulate the speed of rotation.

Also you may want to try something like:

 newRot= transform.rotation * Quaternion.Euler(0, 90, 0);

That would avoid all the if and simply add 90 degrees to the existing rotation.

EDIT: It probably does not do anything because it should be :

 newRot= playergraphic.transform.rotation * Quaternion.Euler(0, 90, 0);
 playergraphic.transform.rotation = Quaternion.Slerp(playergraphic.transform.rotation, newRot, Time.time * RotSpeed);
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smirlianos · May 10, 2013 at 12:14 PM 0
Share

Now it doesn't turn at all!

avatar image smirlianos · May 10, 2013 at 01:09 PM 0
Share

Oh yes! It was so simple! Thanks!

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use Lerp to rotate object 2 Answers

instant rotate an object 3 Answers

How do I rotate a quaternion with euler angles? 0 Answers

How can I use lerp to rotate an object multiple times? 2 Answers

Quaternion.Euler and Quaternion.Slerp problem when using *= Add!! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges