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
1
Question by Onyzora · Nov 08, 2016 at 09:34 AM · camerarotation axisquaternionstop down

Top down camera always facing north - avoid residual rotation

Hi

I'm making a top down racing game with a 3D perspective camera (so in a 3D world). I want my camera to face the vehicle with a restriction in angles (horizontal an vertical relative to the camera) and never rotate around its z axis (so the local up of the camera is always north).

alt text

Basicaly, when the vehicle is on a slope and align with the ground normal, the camera moves slightly to accomodate the new position, then rotate to face again the vehicle, as pictured:

alt text

Problem is, after some slopes and movements, the camera takes a little bit of rotation, so it is no longer aligned to north.

alt text

This is roughlty the code of the camera rotation (in LateUpdate):

 void ManageCameraRotation() {
    Vector3 cameraDirection = (target.position - transform.position);
    Quaternion rot = Quaternion.LookRotation(cameraDirection, transform.up);
     
    Vector3 v = rot.eulerAngles;
    //clamping angles should be here ^^^ I think?
    Quaternion desiredRotation = Quaternion.AngleAxis(v.y, Vector3.up) * Quaternion.AngleAxis(v.x, Vector3.right) * Quaternion.AngleAxis(v.z, Vector3.forward);
             
    transform.localRotation = Quaternion.Slerp(transform.localRotation, desiredRotation, Time.deltaTime * 5.0f);
 }

I don't understand Quaternions enough to know where to lock the rotation in desiredRotation. Or should I manually rotate the camera back to north when the vehicle is facing up (no normals)?

Thanks!

quaternion-unity-b.jpg (59.7 kB)
quaternion-unity.jpg (145.1 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 MERCURY_GAME_CREATOR · Nov 08, 2016 at 10:41 AM

Make the camera a child of the racer. Hope it helps ;)

Comment
Add comment · Show 1 · 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 Onyzora · Nov 08, 2016 at 03:55 PM 0
Share

I don't think it would be suitable since the camera moves independently from the racer, and has to be restrained so if the vehicle is rolling over, the camera wouldn't make weird things.

But thanks anyway it gaves me an idea I'll try something :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternions; how do I rotate an object around only 2 axis based on another rotation? 1 Answer

Rotating a camera and his object like an airplane simulator 2 Answers

Top-Down Camera: Always looking where the player is facing? 1 Answer

Rotate object instead of camera around it? 0 Answers

How do I get my camera to rotate around the y=0 coordinate it's looking at? 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