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 DigitalOranges · Apr 29, 2011 at 11:05 AM · camerarotateplanepitchyaw

Camera pitch/yaw relative to plane

I'm developing an astronomy/planetarium application in Unity and I've come across a problem.

I need to set the camera pitch/yaw (altitude/azimuth) relative to a ground plane (so the 'horizon' is always parallel to the bottom of the screen). The cameras parent transform is the ground plane and if I adjust the local rotation of the camera on either the horizontal or vertical axis, it seems to work, but if I adjust both at the same time, the camera twists and the 'horizon' rotates.

I'm sure I'm missing something here and I've searched on the forum for an answer, but nothing seems to work. Although I'm not new to programming, I'm fairly new to 3D programming so a little nudge in the right direction would certainly help me out. :-)

Comment
Add comment · Show 1
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 Joshua · May 05, 2011 at 02:48 PM 0
Share

Are you trying to make something similair to this? http://www.kongregate.com/games/Josh_Amsterdam/space-exploration

If you like I'd pass you on the camera script :)

2 Replies

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

Answer by Bunny83 · Apr 29, 2011 at 11:30 AM

Well, i guess Transform.Rotate will do the job. The default space is local space, so it rotates around the local axis.

I don't get your camera problem. If the camera is a child of your plane it will move and rotate with the plane whatever the plane is doing. Or in other words: What should your camera do? If you want a smooth following camera don't add it as child. There's a smoothFollow script in the standard assets that would do the job.


edit
Ok if i got that right your camera is mounted at the center (like in a planetarium) and there's some kind of hemisphere around your camera. Now you want to turn/pitch the camera to look at a certain point by giving the heading(azimuth) and a pitch(polar angle/altitude). Well to accomplish such a rotation you have to keep in mind that if you rotate the camera around the local x axis, the local upvector will tilt. So the azimuth angle have to be applied globally. If your whole scene is stationary you can just use Rotate with Space.World. If your "plane" can move/tilt you have to use RotateAround with the up vector of your plane.

transform.RotateAround (transform.position, transform.parent.up, azimuth);
transform.Rotate (altitude, 0, 0);

The two angles here are delta values. If you want to setup a rotation with absolute angles just use a Quaternion:

transform.localRotation = Quaternion.Euler (altitude, 0, 0) * Quaternion.Euler (0, azimuth, 0);

If i don't messed up the order that should work ;)

Comment
Add comment · Show 2 · 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 DigitalOranges · Apr 29, 2011 at 01:06 PM 0
Share

I need the camera to be a child of the plane as the plane itself is parented to a sphere that is rotating. So, regardless of whatever the plane is doing, I need to be able to say to the camera 'point 280 degrees round and 45 degrees up from the ground

avatar image DigitalOranges · Apr 30, 2011 at 10:56 AM 0
Share

Thank's for the help, it worked!

avatar image
0

Answer by matt 2.du · May 05, 2011 at 02:34 PM

well by the looks of things u are using what the guy below has said. if ican explain things in 1 word that would be the Gimbal lock effect basically its when the camera is trying to find 2 axes in a 3d space and it rotating around around them it doesnt simply rotate around both at the same time it works on 1 ie the x then the y then the z axis so when both rotate it may come outt that the camera is turned in to a human rolercoaster this can also be explained by what the guy above has offered being the eualer which is basically a follow but when say in a flight sims case the players plan flips because the object always wants to not excede the 90 degree mark. what you need to do is remove it. im not sure but a while ago there was 1 on this forum. try searching for how to fix camera fliping or something of that nature. if you do not wish to go to that effert you could simply make a max rotation angle so the player doesnt flip do an if statement like

planatarium roation style if (object>objectanglerotation.x) {objectanglerotation.x}

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

How to rotate the planar region to alway face the camera? 2 Answers

pitch camera up and down... 1 Answer

Change characters direction using camera view 0 Answers

Create plane in cam's view frustum x units away 0 Answers

WebCamTexture zoomed in on iPad Pro 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