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 /
avatar image
0
Question by User Banned · Nov 03, 2012 at 08:31 AM · resetslerp

Reset slerp to.rotation to avoid follow through

Good day to you fellow humans,

Im a little puzzled by the following and wish to seek the assistance of someone cleverer than myself. I would like to reset a to.rotation after slerping to the current transform.rotation to avoid continuing the previous slerp the next time the code is called.

This is the relevant part, works fine:

         if (Input.GetMouseButton (0)) {
             rotationX += Input.GetAxis ("Mouse X") * cameraSensitivity * Time.deltaTime;
             rotationY += Input.GetAxis ("Mouse Y") * cameraSensitivity * Time.deltaTime;
             rotationY = Mathf.Clamp (rotationY, -90, 90);
 
             Rotat = Quaternion.AngleAxis (rotationX, Vector3.up);
             Rotat *= Quaternion.AngleAxis (rotationY, Vector3.left);
 
             transform.rotation = Quaternion.Slerp (transform.rotation, Rotat, Time.deltaTime * LookDamping);
         }

Now i would have thought that adding this...

         if (Input.GetMouseButtonUp (0)) {
              Rotat = transform.rotation;
         }

...would stop the camera rolling on to the previous target rotation the next time the button is clicked, but it doesnt seem to do anything.

Any thoughts?

Comment
Add comment · Show 6
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 whydoidoit · Nov 03, 2012 at 11:03 AM 0
Share

Well as you are only Slerping when the button is down it should stop moving anyway - something else must be rotating it!

avatar image User Banned · Nov 03, 2012 at 03:10 PM 0
Share

Sorry obviously didnt make myself clear enough.

The problem is not a continuation of rotation on mouse button up (it does stop), the problem is the continuation of the previous rotation trajectory when the button is pressed again.

Therefore i am attempting to reset 'Rotat' to the current rotation.

avatar image whydoidoit · Nov 03, 2012 at 04:55 PM 0
Share

Looks to me like you need to reset rotationX and rotationY to 0 then...

avatar image User Banned · Nov 03, 2012 at 05:32 PM 0
Share

No that just springs the rotation to zero next time the button is pressed, as does setting rotationX/Y to transform.rotation.x/y, I recall now its one of the many things I have tried before resorting to asking here.

I suppose though the solution must lie in translating the current rotation back to the RotationX/Y variables. But transform.rotation is an angle, RotationX is some random float, is this possible?

avatar image whydoidoit · Nov 03, 2012 at 05:58 PM 0
Share

Looks to me like it will be the eulerAngles of the current rotation x = -transform.rotation.eulerAngles.z and rotation y = transform.rotation.eulerAngles.y

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by User Banned · Nov 03, 2012 at 10:05 PM

Following code was the answer, got there in the end, though not sure i totally understand the logic of it.

         if (Input.GetMouseButtonUp (0)) {
             rotationX = transform.eulerAngles.y;
             rotationY = (0 - transform.eulerAngles.x);
         }

As you can see RotationX/Y are flipped from eulerangles.x/y, not sure why it should be like that but it works so hey. Thanks whydoidoit for prodding in the right direction.

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 whydoidoit · Nov 04, 2012 at 05:56 AM 0
Share

It's flipped because you are using Vector3.left - I didn't even know that existed!!!!

The axes of rotation are forward, right and up.

avatar image User Banned · Nov 04, 2012 at 12:18 PM 0
Share

Well that makes sense, duly changed.

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How do I rotate on World Axes with Quaternion.Slerp? 2 Answers

Slerp/Rotational Problem Query 1 Answer

How to use Slerp / Lerp / RotateTowards to rotate an object (from-to) two rotations but around their Y axis only? 0 Answers

Trying to move an object in an arc around the player 3 Answers

only look at the player if the raycast is not hitting the obstacle. 1 Answer


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