Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 gilgada · May 15, 2012 at 06:32 PM · rotationcharactercontrollerplanetcompassfauxgravity

Always rotate the camera to be stood close to upright.

Hi, I have a faux gravity system set up and the player can control a character collider around a sphere. The camera is attached to this and looks down onto the surface of the sphere (textured as the earth). The problem is that while the player can shift the position of the character controller up and down the surface as well as left and right (strafing), they can eventually lose the correct orientation.

For example, the camera could be looking at Italy on the sphere surface texture just fine but once the player has moved them around the planet, the boot-shaped Italy can become rotated. A better example is Australia, after moving up past the north pole, the sphere has effectively started to flip upside down and upon reaching Australia, the view would show it flipped around.

I need to be able to keep the camera or character controller in the right orientation. Obviously, the character's rotation and position are constantly changing when moving around the sphere, but I am wondering if there is a way to get the character to rotate to have the right 'map' orientation, i.e as with a compass needle always facing the north pole.

Comment
Add comment · Show 3
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 asafsitner · May 15, 2012 at 07:56 PM 1
Share

Doesn't LookAt (worldPosition : Vector3, worldUp : Vector3 = Vector3.up) work properly? It's supposed to keep the up orientation of the looking object along the specified up vector.

Another option could possibly be rotating the sphere as opposed to moving the player, but that could cause no less trouble so I'm not sure if it's worth trying. Just tossing the idea there.

avatar image gilgada · May 15, 2012 at 09:23 PM 0
Share

Thankyou, I shall have a look at LookAt ;)

Also, would you care to submit your comment as an answer so that if it works I can give you the relevant praise and put this question to bed?

avatar image gilgada · May 15, 2012 at 10:43 PM 0
Share

hmmm it did not seem to have the desired effect. I added it to the faux gravity script on the character controller. It does seem to make the character controller look at an object I have placed above the northern pole but as the camera is attached, the player's view is pretty bad.

1 Reply

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

Answer by hathol · May 15, 2012 at 11:11 PM

You could check the dot product of the camera.transform.up vector and Vector3.up. If the result is negative (= the angle in between the vectors is > 90) then flip the camera (rotate 180 degrees around transform.forward) so that it's up vector is actually pointing upwards again.

Comment
Add comment · Show 7 · 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 gilgada · May 15, 2012 at 11:38 PM 0
Share

I have taken your advice and tried to incorporate a check against the dot product. I have the following in the FixedUpdate of my player's fauxgravity script.

Vector3 toPole = northPole.position - transform.position; Vector3 forward = transform.TransformDirection(Vector3.forward);

         if(Vector3.Dot(forward, toPole) < 0)
         {
             this.transform.RotateAround(transform.forward, 180);
         }

where northPole is the transform of a cube positioned at the top of the sphere.

Problem is, past a certain point the camera will constantly rotate in a spasm.

avatar image hathol · May 15, 2012 at 11:46 PM 1
Share

Probably because your forward vector never changes, so it just keeps rotating. Did you try

 if(Vector3.Dot(transform.up, Vector3.up) < 0)
 {
     this.transform.RotateAround(transform.forward, 180);
 }

?

avatar image gilgada · May 15, 2012 at 11:51 PM 0
Share

just tried this and it still repeats the process over and over, is it because i have it in FixedUpdate?

avatar image hathol · May 16, 2012 at 12:01 AM 1
Share

Hm. Is that script attached to your controller or the camera itself? If it's on the controller, attach it to the camera ins$$anonymous$$d. Whether you execute it in Update or FixedUpdate shouldn't make much of a difference then...

If the script needs to stay on the controller for some reason, get a reference to the camera and use camera.transform.up and camera.transform.forward

avatar image gilgada · May 16, 2012 at 12:46 PM 0
Share

Hmmm, this seems to have some effect but the problem is the character controller still remains in the same orientation so the controls become inverted from the player's viewpoint.

The rotation when switching is also instant. I need the camera to always stay at a certain orientation so as to always point upwards to the pole.

Show more comments

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with rotating a character that has faux gravity 1 Answer

Rotating horizontally around a sphere 1 Answer

Make UI compass point to 3D object 4 Answers

Character Controller slides sideways when it hits objects are angles different from 90 degrees 1 Answer

Get real compass direction 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