Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by dipam · Apr 05, 2016 at 05:59 AM · rotationlerp

I am using Quaternion.Slerp to rotate an object from -30 to 30 (rotating fine). But i am unable to make the reverse rotation from 30 to -30. Please help me how to do that reverse rotation?

I am working in a demo game project in which, there is a tower that shot bullets and can rotate from -30 to +30 then +30 to -30 and continue this rotation forever. I am having problem with roatation. I am using Quaternion.Slerp to rotate it from -30 to 30 (rotating fine). But i am unable to make the reverse rotation from +30 to -30. Please help me how to do that reverse rotation. I am new to Unity. Thank you! //Here is my code

 using UnityEngine;
 using System.Collections;
 
 public class RotateTo : MonoBehaviour
 {
 
     private Quaternion rotationFrom;
     private Quaternion rotationTo;
 
     void Start () {
         
 
         rotationFrom = Quaternion.Euler(0.0f, -30, 0.0f);
         rotationTo = Quaternion.Euler(0.0f, 30, 0.0f);
         
     }
     // Update is called once per frame
     void Update ()
     {
         transform.rotation = Quaternion.Slerp(rotationFrom, rotationTo, 0.5f * Time.time);
     }
 }
 
 
Comment
Add comment · Show 1
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 Cyb3r_Kid · Apr 05, 2016 at 12:31 PM 1
Share

You could try making the Quaternion.Euler a new Vector3. Otherwise it looks fine. The Quaternion.Slerp API shows that you have the time and speed flip flopped but I am not sure if that would make a difference.

1 Reply

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

Answer by Mike-Geig · Apr 06, 2016 at 03:24 AM

You're close, you just need to flip flop the numbers when you reach your goal:

 private Quaternion rotationFrom;
 private Quaternion rotationTo;
 
 float ellapsedTime = 0f;
 
 void Start () {
 
 
     rotationFrom = Quaternion.Euler(0.0f, -30, 0.0f);
     rotationTo = Quaternion.Euler(0.0f, 30, 0.0f);
 
 }
 // Update is called once per frame
 void Update ()
 {
     ellapsedTime += Time.deltaTime;
     transform.rotation = Quaternion.Slerp(rotationFrom, rotationTo, 0.5f * ellapsedTime);
 
     //if we get within a 10th of a degree...
     if (Quaternion.Angle (transform.rotation, rotationTo) < .1f) 
     {
         //Start our time over
         ellapsedTime = 0f;
 
         //Flip flop our values
         Quaternion temp = rotationTo;
         rotationTo = rotationFrom;
         rotationFrom = temp;
     }
 }
Comment
Add comment · Show 1 · 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 dipam · Apr 06, 2016 at 05:42 AM 0
Share

Thank you $$anonymous$$r. $$anonymous$$ike. This is perfectly what i want.

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

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

Related Questions

Is it possible to rotate an object around its z-axis without changing its x-axis and y-axis? 1 Answer

Object rotation lerp with acceleration 0 Answers

Slerp rotation issue when calling a lot 0 Answers

Movement and Direction script bugging out 1 Answer

How to set the time value in Lerp, Slerp, RotateTowards? 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