• 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 /
avatar image
Question by 10001110101 · Sep 02, 2013 at 03:15 AM · camerarotationtransformslerpdeltatime

Quaternion Slerp Sanity Check

Been a long day here,

Does anyone see any glaring issues with t$$anonymous$$s:

 //Rotate the object based on the up axis of the target. (With Interpolation)
     transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(transform.forward,target.up),Time.deltaTime * 0.2f);

Thanks,

T

Comment

People who like this

0 Show 4
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 Adamcbrz · Sep 02, 2013 at 03:22 AM 0
Share

really need more context to have any clue.

avatar image 10001110101 · Sep 02, 2013 at 03:25 AM 0
Share

Updated. Added Comments.

avatar image aldonaletto · Sep 02, 2013 at 09:56 AM 0
Share

The only thing this code does is to slowly rotate about the object's local forward direction until its upper side aligns to the target's up direction - provided that the code is inside a periodic function like Update, FixedUpdate, LateUpdate, coroutine loop etc (like @CHPedersen said below). Is this what you want to do?

avatar image 10001110101 · Sep 02, 2013 at 07:36 PM 0
Share

Yes, however it is not behaving as desired for some reason. I'm examining that second parameter under a microscope currently to see if that is the problem per @CHPedersen's advice.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by CHPedersen · Sep 02, 2013 at 06:04 AM

It depends on what exactly that line of code is meant to do for you, of course. If you're just using t$$anonymous$$s line of code to set the rotation of that transform once, then it might be just fine. But since you're using Time.deltaTime, it indicates you're trying to use t$$anonymous$$s to animate the rotation change, maybe in a coroutine? If that is the case, then one t$$anonymous$$ng that might be confusing is the fact that you're using variables w$$anonymous$$ch change on every iteration to define the endpoints of the linear interpolation. You can use lerp that way, and sometimes it makes sense to do so, such as situations where you want the start-point to chase the result so that the animation eases to a stop instead of moving with uniform speed.

The second parameter is more troublesome. Note that you're accessing transform.forward in that call to Quaternion.LookRotation when you're defining the endpoint. But transform.forward changes every time the rotation is set. It's the object's local forward (the blue arrow) after all; it points in a different direction every time the rotation is changed. That's gonna make the behavior of that Slerp's endpoint really hard to understand. If it's not behaving the way you expect, consider defining constant start- and endpoints and save them to variables outside the Slerp.

Comment
aldonaletto
10001110101

People who like this

2 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 10001110101 · Sep 02, 2013 at 07:33 PM 0
Share

I think I understand what you are saying. So, my intent is to update the rotation of a camera based on the forward and up vector of the target automatically. Using Time.deltaTime * (x) where x is a speed, allows the interpolation to step in on itself as long as the first argument is the same as the variable that the Slerp is assigning to, correct?

avatar image CHPedersen · Sep 02, 2013 at 07:40 PM 0
Share

Exactly. That's what I meant by having the start-point "chase the result". ;) What you said is just a different way to describe usage of Lerp, where you gradually decrease the range between start and stop in order to also decrease the step-length, i.e. slow down the animation.

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

nullifying targetObject after a Smooth LookAt Transition 2 Answers

Rotating gameobject after mouselook 0 Answers

How to make Camera position Independent of its Rotation? 1 Answer

Rotation always changing values! 1 Answer

Camera transform not responding after load 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