• 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 heldt · Jan 06, 2020 at 07:33 AM · rotation axis

Gameobject rotation differs between display/monitors

I'm facing a problem when I'm rotating a gameobject 90 degrees. When I have my unity editor or my compiled game on my primary screen. The cube only rotates, what it looks like, 45 degrees. But in the inspector the gameobjects z rotation is 90 degrees.

When I have my game running or unity editor on my secondary screen it works as intended and rotates my cube 90 degrees.

I can't seem to find the cause of why the game behaves like this. Anyone know what i'm doing wrong?

Primary monitor. Rotation not working Primary monitor. Rotation not working

Secondary monitor. Rotation working Secondary monitor. Rotation working

My player controller for rotation

 using UnityEngine;
 using UnityEngine.Events;
  
 public class playercontroller : MonoBehaviour
 {
  
     [SerializeField]
  
     [Header("Smash  event")]
     public UnityEvent smashEvent;
  
     private float speed = 3.500f;
     private bool rotating = false;
  
     float currentRotationAngle = 0f;
     float targetRotationAngle = 90f;
  
     Vector3 rotationAxis = new Vector3(0f, 0f, 0f);
  
     private bool smashing = false;
  
  
     // Start is called before the first frame update
     void Start()
     {
         if (smashEvent == null)
         {
             smashEvent = new UnityEvent();
         }
     }
  
  
     void OnDrawGizmos()
     {
     }
  
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.W) && !rotating)
         {
             print("w");
             rotationAxis = new Vector3(0f, 0f, 1f);
             rotating = true;
         }
         else if (Input.GetKeyDown(KeyCode.S) && !rotating)
         {
             print("S");
             rotationAxis = new Vector3(0f, 0f, -1f);
             rotating = true;
         }
         else if (Input.GetKeyDown(KeyCode.A) && !rotating)
         {
             print("A");
             rotationAxis = new Vector3(0f, 1f, 0f);
             rotating = true;
         }
         else if (Input.GetKeyDown(KeyCode.D) && !rotating)
         {
             print("D");
             rotationAxis = new Vector3(0f, -1f, 0f);
             rotating = true;
         }
         else if (Input.GetKeyDown(KeyCode.R))
         {
         }
         else if (Input.GetKeyDown(KeyCode.Space))
         {
             print("dispathc");
             smashEvent.Invoke();
         }
  
  
         if (rotating)
         {
             var angle = Mathf.LerpAngle(0, targetRotationAngle, speed * Time.deltaTime);
             var nextAngle = Mathf.Abs(currentRotationAngle + angle);
  
             if (nextAngle > targetRotationAngle)
             {
                 var lastRotation = Mathf.Abs(currentRotationAngle - targetRotationAngle);
                 transform.Rotate(rotationAxis, lastRotation, Space.World);
                 rotating = false;
                 currentRotationAngle = 0f;
             }
             else
             {
                 transform.Rotate(rotationAxis, angle, Space.World);
                 currentRotationAngle = currentRotationAngle + angle;
             }
         }
     }
 }

,

working-rotation-90.png (157.7 kB)
primary-monitor-not-working-after-rotation-90.png (151.7 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by heldt · Jan 12, 2020 at 10:12 PM

I solved it by locking the fps to 60 fps.

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.

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

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

Bugs, bugs and bugs again! 0 Answers

have enemy try to get in front of player and push them back help 0 Answers

How to make the object return to its last angle (before the angle limit) go back no so abruptly ? 0 Answers

How can I flip a player over the Horizontal and Vertical axis? 0 Answers

Align two cameras to a fixed position 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