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 /
avatar image
0
Question by mirkojpn · Apr 09, 2018 at 03:23 AM · rotationquaternionrotaterotatearoundeuler

instant rotate an object

Hello everyone.

i'm trying to instant rotate my shark that is moving between two point with pingpong, i'm noob and i can't figure out how to do it, i already tried many things, transform.rotate(doesn't instantly rotate it), and also i tried with checkpoints, when hit the checkpoint1 collider2d it will rotate, but doesn't work, maybe it's a really stupid things but i can't figure out how to do it, anyone can help me? this is the code.

     private Vector2 pos1 = new Vector2(21.00f,-4.04f);
     private Vector2 pos2 = new Vector2(36.00f,-4.04f);
 
 
 
     
 
     public float speed = 1.0f;
 
 
 
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         transform.position = Vector2.Lerp(pos1, pos2, Mathf.PingPong(Time.time * speed,1.0f));
 
         
 
     }
 
     void OnTriggerEnter2D (Collider2D other) {
         if(other.tag == "checkpoint1") {
             transform.rotation = Quaternion.Euler(0,-180,0);
         }
         else if(other.tag == "checkpoint2") {
             transform.rotation = Quaternion.Euler(0,180,0);
         }
     }
 
 }
 
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

3 Replies

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

Answer by Eno-Khaon · Apr 09, 2018 at 04:29 AM

By your uses of transform.rotation in your script example, you're setting the same rotation in both cases.

Because Euler angles use a range from 0-360 degrees for a full rotation (and any other number can be converted into that range), the values you use of 180 and -180 both resolve to the same value of 180 degrees.

That said, there are numerous ways to implement this, so here's another example as food for thought:

 Quaternion noRotation = Quaternion.AngleAxis(0.0f, Vector3.up);
 Quaternion halfRotation = Quaternion.AngleAxis(180.0f, Vector3.up);


With this in mind, you could also potentially just reuse the halfRotation every time you want to change direction (with a very slight possibility of visible error in facing after many, many, MANY hours)

 transform.rotation *= halfRotation;
Comment
Add comment · 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
0

Answer by saml_baker · Apr 09, 2018 at 03:40 AM

Try using Rigidbody.rotation. It will let you teleport between rotations using the rigidbody.

Comment
Add comment · 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
0

Answer by mirkojpn · Apr 09, 2018 at 04:28 AM

thank's you for your answer, i read that RigidBody2D.rotation is going to rotate the z axis, but what i need is to rotate de y axis.

Comment
Add comment · 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

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

111 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 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

How do I rotate a game object in 45 degree steps per keystroke? 2 Answers

Rotate object in the direction where it is going 1 Answer

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

Quaternion.Slerp problem... 1 Answer

Rotation with a slider 2 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