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 EMOTION-THEORY · Nov 10, 2013 at 02:14 AM · cameraphysicsgravityhud

Face object towards a "direction" Crazy Taxi style

Hey everyone,

I have a compass needle that I've placed on a separate camera/layer so that it appears as a HUD object.

What I want is for this needle to face the direction that the gravity is set to.

When the player rotates the main camera, the needle should also rotate and point towards the direction of gravity at all times.

I'd also like to know how to do this to, say, the North direction (when the player looks down, the needle should also rotate).

I've got this, but it still doesn't respect the camera's rotation, only the gravity:

 transform.forward = -Physics.gravity;

Thanks!

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 Cains · Nov 10, 2013 at 05:32 AM

As I understand it your needle is in a camera separate from your main camera, and therefore by default it's not affected by your main camera at all because it's completely separate.

What you want to do is in the Update() function of the second camera with the needle, orbit the camera around the needle by the transform.rotation of the main camera. If you don't understand what I mean I can probably whip something up really quick to show you.

If you wanted to do this for North instead of gravity you'd just set the transform.forward of the needle to the direction you want to be North. For example

 transform.forward = new Vector3(1,0,0);

would point the needle in the positive x direction if you wanted that to be North.

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 EMOTION-THEORY · Nov 17, 2013 at 11:12 PM 0
Share

Thanks for your response.

If I understand correctly, using pseudocode, it would look something like:

cam2.orbit(cam1.transform.rotation);

How would you orbit a camera around an object?

Also, rather than actually have the camera orbit the object, is there a way for the camera to remain static, but have the compass needle itself rotate based on the first camera's rotation? That was the answer I was looking for.

So effectively it would rotate based on cam1. So:

compass.transform.forward = cam1.transform.forward; compass.transform.rotation += gravityOffset; // Or, offset the makes it point north.

Thanks again!

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

17 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

Related Questions

Rotating FPC Causes Player To Pass Through Surfaces 2 Answers

Help with orbits 1 Answer

Falling object, change its angle 0 Answers

Affecting FPS controller/Character Motor physics with game object 1 Answer

I am getting LOW Fps, because of simple Physics. Help. 5 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