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 LegacyOfGames · Jan 05, 2017 at 04:42 PM · rotationbuggravitybug-perhapsangleaxis

Trouble with rotating player when gravity is shifted

Not sure if this is the place to ask because this is a very specific bug, but what the hey.

I'm working on a 3D mechanism in which the player can shoot at a wall to determine it as the new floor, allowing for 6 different "gravities" in the game (the environment is a connected series of boxes). I've gotten it to work perfectly on 4 of the 6 directions, but somehow the front and back walls (the two walls along the global Z axis) give me the strangest trouble.

Below is my cameraController script. The sensitivity\smoothing bit was copy-pasted from a youtube tutorial, but I can't see any fault in it. I've also set constraints on the player's rigidbody, freezing rotation on X and Z axes and leaving only Y free. Removing these constraints doesn't fix anything, it only makes the player sway towards the direction he is rotating and tip over.

     mouseInputX = Input.GetAxisRaw("Mouse X") * sensitivity * smoothing;
     mouseInputY = Input.GetAxisRaw("Mouse Y") * sensitivity * smoothing;
     smoothX = Mathf.Lerp(smoothX, mouseInputX, 1f / smoothing);
     smoothY = Mathf.Lerp(smoothY, mouseInputY, 1f / smoothing);
     mouseLookX += smoothX;
     mouseLookY += smoothY;
     mouseLookY = Mathf.Clamp(mouseLookY, minimumY, maximumY);

     transform.localRotation = Quaternion.AngleAxis(mouseLookY, Vector3.left);
     player.transform.rotation = Quaternion.AngleAxis(mouseLookX, -gameController.gravityVector);

     if (gameController.gravityVector == Vector3.forward) //still buggy!
     {
         player.transform.eulerAngles += new Vector3(-90, 0, 0);
     }
     else if (gameController.gravityVector == Vector3.right)
     {
         player.transform.eulerAngles += new Vector3(0, 0, 90);
     }
     else if (gameController.gravityVector == Vector3.back) //still buggy!
     {
         player.transform.eulerAngles += new Vector3(90, 0, 0);
     }
     else if (gameController.gravityVector == Vector3.left)
     {
         player.transform.eulerAngles += new Vector3(0, 0, -90);
     }
     else if (gameController.gravityVector == Vector3.up)
     {
         player.transform.eulerAngles += new Vector3(0, 0, 180);
     }

The trouble I'm getting is that when, for instance, gravity is set to the front wall (gameController.gravityVector == Vector3.forward). Looking up and down (rotating around Vector3.left which is -1,0,0) works perfectly fine, but looking left and right (rotating around -gameController.gravityVector) rotates the player around his personal Z axis instead of his Y axis. Mind that the problem doesn't happen on the floor, ceiling and side walls.

I've tried conditioning the rotation for each wall separately, and toy with the axis I give the AngleAxis function. This is where I got super stuck, because both Vector3.down and Vector3.back identically rotate my player around his freaking Z axis! (Vector3.up and Vector3.forward are also identical to each other, yielding an inverse rotation around the Z axis).

I am all out of ideas on how to fix this, and am beginning to believe AngleAxis has a bug.

Whoever helps me solve this will earn my undying gratitude, which may very well manifest in the form of a pizza.

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

101 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

Related Questions

Object rotates normaly while moving, then does zig zags? 0 Answers

Moving an Plane via numerical input to transform box alters it's rotation degree value slightly 0 Answers

how can I align a rotating block that falls onto another with the correct face? 2 Answers

WHAT THE HECK? Rotations not working. 0 Answers

Error when trying to upload a package to the unity asset store (file not found, loader.html) 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