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 Praelatos · May 09, 2016 at 07:19 PM · rotationtransforminternal

What is transform.Rotate doing internally when going beyond 360° or 0°?

Title says it all. The reason why I'm asking this is because I have Vector3 points which should follow the corner points of a cube. It's kinda working but there appear to be "2 sections of 360°". At the start everything works fine but if the rotation goes beyond 360° or below 0° the vectors rotate in the opposite direction of the cube until the rotation goes beyond 360° degrees again. using UnityEngine;

 public class Move : MonoBehaviour {
 
     float movespeed;
     float rotspeed;
 
     Vector3 pointA = new Vector3();
     Vector3 pointB = new Vector3();
     Vector3 pointC = new Vector3();
     Vector3 pointD = new Vector3();
     Vector3 pointE = new Vector3();
     Vector3 pointF = new Vector3();
     Vector3 pointG = new Vector3();
     Vector3 pointH = new Vector3();
 
     void Awake() {
         
         // force 60 fps
         Application.targetFrameRate = 60;
     }
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
 
         movespeed = Input.GetAxisRaw("Vertical") * Time.deltaTime;
         if (movespeed > 0) movespeed *= 4;
         transform.Translate(0, 0, movespeed);
 
         rotspeed = Input.GetAxisRaw("Horizontal") * Time.deltaTime * 60;
         transform.Rotate(0, rotspeed, 0);
 
         // initialize corner points of bounding box
         pointA.Set(-0.5f, 0, -0.5f);
         pointB.Set(0.5f, 0, -0.5f);
         pointC.Set(0.5f, 0, 0.5f);
         pointD.Set(-0.5f, 0, 0.5f);
         pointE.Set(-0.5f, 1f, -0.5f);
         pointF.Set(0.5f, 1f, -0.5f);
         pointG.Set(0.5f, 1f, 0.5f);
         pointH.Set(-0.5f, 1f, 0.5f);
 
         // rotate around y-Axis with transform's y-rotation
         pointA = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointA;
         pointB = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointB;
         pointC = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointC;
         pointD = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointD;
         pointE = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointE;
         pointF = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointF;
         pointG = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointG;
         pointH = Quaternion.AngleAxis(transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointH;
 
         // translate points to transform's position
         pointA.x += transform.position.x;
         pointB.x += transform.position.x;
         pointC.x += transform.position.x;
         pointD.x += transform.position.x;
         pointE.x += transform.position.x;
         pointF.x += transform.position.x;
         pointG.x += transform.position.x;
         pointH.x += transform.position.x;
 
         pointA.y += transform.position.y - 0.5f;
         pointB.y += transform.position.y - 0.5f;
         pointC.y += transform.position.y - 0.5f;
         pointD.y += transform.position.y - 0.5f;
         pointE.y += transform.position.y - 0.5f;
         pointF.y += transform.position.y - 0.5f;
         pointG.y += transform.position.y - 0.5f;
         pointH.y += transform.position.y - 0.5f;
 
         pointA.z += transform.position.z;
         pointB.z += transform.position.z;
         pointC.z += transform.position.z;
         pointD.z += transform.position.z;
         pointE.z += transform.position.z;
         pointF.z += transform.position.z;
         pointG.z += transform.position.z;
         pointH.z += transform.position.z;
 
         // draw bounding box
         Debug.DrawLine(pointA, pointB, Color.red, 0, false);
         Debug.DrawLine(pointA, pointD, Color.red, 0, false);
         Debug.DrawLine(pointB, pointC, Color.red, 0, false);
         Debug.DrawLine(pointC, pointD, Color.red, 0, false);
         Debug.DrawLine(pointA, pointE, Color.red, 0, false);
         Debug.DrawLine(pointB, pointF, Color.red, 0, false);
         Debug.DrawLine(pointC, pointG, Color.red, 0, false);
         Debug.DrawLine(pointD, pointH, Color.red, 0, false);
         Debug.DrawLine(pointE, pointF, Color.red, 0, false);
         Debug.DrawLine(pointE, pointH, Color.red, 0, false);
         Debug.DrawLine(pointF, pointG, Color.red, 0, false);
         Debug.DrawLine(pointG, pointH, Color.red, 0, false);
 
         Debug.Log(transform.eulerAngles.y);
     }
 }

I know how to fix this by checking in which "360° section" I am and writing it like this for the other "section":

 pointA = Quaternion.AngleAxis(360f - transform.eulerAngles.y, new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)) * pointA;

Thanks in advance!

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make spot light trace player? 0 Answers

How to Move the rotated Game Object Forward 0 Answers

Translating measurement in rotation speed and game object size to non-technical staff 0 Answers

Camera Rotating Around GameObject Bugs Out 0 Answers

Instant Transform.Rotate? 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