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 MohsenneChaverdie · Dec 25, 2016 at 01:08 PM · rotationplayerpivotworld

World Rotation Around The Player Lead me to a Strange Result!

I want to rotate the world around the player position. Since I wanted this rotation to be not instant, nor controlled by time, neither based on duration of pressing a button, I used Animation Window. I am rotating the world to right when the player presses right. Because I wanted the world to rotate around the player, I created an empty game object and put the world into it and made it a child of the world to have a pivot point. As long as the world has not been rotated to any direction, world pivot works fine. If the world rotates to the right by 90 degree, the x and y of the pivot points turns out to be the opposite of y and x of the player position. I am changing those values for the world, but this time, pivot and the world acting very strange. When I am changing the player to right, the world moves a little bit in up direction.

Since it is an Uni project, I will appreciate any help. I am in need of urgent help. Note: The script below is attached to the player.

     void Update()
     {
         RotateWorldAroundPivot();
         CheckForGrounded();
         Movement();
         StartCoroutine(playerFreeze());
         Jump();
         StartCoroutine(WorldRotation());
         Fall();
     }
 
     IEnumerator playerFreeze()
     {
         if (rigidBody2D.velocity.y > 1)
         {
 
             yield return new WaitForSecondsRealtime(0.8f);
 
             Time.timeScale = 0.0001f;
             canRotatetheWorld = true;
             yield return new WaitForSecondsRealtime(2.5f);
             Time.timeScale = 1f;
             canRotatetheWorld = false;
         }
     }
 
     IEnumerator WorldRotation()
     {
         if (canRotatetheWorld == true)
         {
             if (angleStatus == "zero" && Input.GetKeyUp("right"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", 1);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "nintyDegree";
             }
             if (angleStatus == "nintyDegree" && Input.GetKeyUp("right"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", 2);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "hundredEightyDegree";
             }
             if (angleStatus == "hundredEightyDegree" && Input.GetKeyUp("right"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", 3);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "minusNintyDegree";
             }
             if (angleStatus == "minusNintyDegree" && Input.GetKeyUp("right"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", 4);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "zero";
             }
             if (angleStatus == "nintyDegree" && Input.GetKeyUp("left"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", -1);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "zero";
             }
             if (angleStatus == "hundredEightyDegree" && Input.GetKeyUp("left"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", -2);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "nintyDegree";
             }
             if (angleStatus == "minusNintyDegree" && Input.GetKeyUp("left"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", -3);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "hundredEightyDegree";
             }
             if (angleStatus == "zero" && Input.GetKeyUp("left"))
             {
                 worldAnimator.SetInteger("WorldRotationAnim", -4);
                 yield return new WaitForSecondsRealtime(0.1f);
                 angleStatus = "minusNintyDegree";
             }
         }
     }
 
     void RotateWorldAroundPivot()
     {
         if (angleStatus == "zero")
         {
             worldToRotate.transform.position = new Vector2(transform.position.x, transform.position.y);
             worldPivot.transform.position = new Vector2(-transform.position.x, -transform.position.y);
         }
         if (angleStatus == "nintyDegree")
         {
             worldToRotate.transform.position = new Vector2(transform.position.x, transform.position.y);
             worldPivot.transform.position = new Vector2(transform.position.y, -transform.position.x);
         }
     }
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

99 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

Related Questions

Camera Rotation Around Player 1 Answer

Camera not rotating alongside player character after new script. 0 Answers

Character Shooting Mechanic 2D Issues 0 Answers

Player's rotation gets stuck when pressing two movement keys together, Player's Rotation breaks when pressing two movement buttons together 0 Answers

TopDown Look at mouse 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