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 Boff · Oct 24, 2012 at 12:42 AM · cameralookatupdownfirstperson

FPS animate camera look up/down

I'm new to unity and I'm trying to get a a "look at" to work in a first person context.

I've written code to snap to in the horizontal plane, by ascertaining the angle via the playerPosition - target position. Then zeroing out the plane we don't want to be rotating on.

And so my first person body rotates neatly around the y axis to point at the object. and re-written it a bunch of times in different contexts to understand what is going on.

But When I apply what I've learned to forcing the camera to look up or down at specific angles/at an object, it appears my understanding of what is going on falls apart (yes the camera is embeded AND i'm using localRotation).

My second attempt is to actually have a secondary "target" camera in the scene LOOKING in the direction where I want the player to be looking. Then take it's local Euler Angles. Zero out the Y and the z because according to my properties panel it's only rotated in x anyway. The previous code will take care of the rotating body around Y.

But by jove this thing is pointing in every direction but the one I want. I wind up looking at the floor or the ceiling, even though the angles are like 15 degrees. I've tried everything Local Eulers, Quaternions, vectors, using the targetcamera.transform.forward as the goal, but none of it works and they all seam to be consistently "wrong". Certain combinations work (no time delta specified so I got an un-animated snap-to, but once I started to animate it goes haywire.) I'll include some extra commented code to show some of my musings.

 var cam_target_direction:Vector3 = targetcamera.transform.localEulerAngles;
 cam_target_direction.y = 0;
 cam_target_direction.z = 0;
 
 var camDirectionQ2:Quaternion = Quaternion.LookRotation(cam_target_direction);
 
 var cam_angleBetweenV2 = Mathf.Floor(Vector3.Angle (localCamera.transform.forward, gimble_target_direction)); 
 
 if (cam_angleBetweenV2 > 1)
     {
         
         
     //    localCamera.transform.localRotation.eulerAngles = Vector3.Slerp(localCamera.transform.localRotation.eulerAngles, cam_target_direction, Time.deltaTime);
     //    localCamera.transform.localRotation = Quaternion.Slerp(localCamera.transform.localRotation, camDirectionQ2, Time.deltaTime* damping*0.5); 
         localCamera.transform.localRotation.eulerAngles.x = Mathf.Lerp(localCamera.transform.localRotation.eulerAngles.x, cam_target_direction.x, Time.deltaTime * damping*0.5);
     }


I can't help but feel I've missed some intrinsical "3d" know how that says you have to rotate the x component around the z component because that just the way it works. Or that the lerp, because the angles work in + and minus and the horizontal is zero, that the camera is trying to loop a whole 345 degrees, instead of nudging the camera down -15. This is like the 3rd attempt at this "y-look" in the last 3 weeks and it's beginning to get to me. I just need help.

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

9 People are following this question.

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

Related Questions

Attaching camera to instantiated object 1 Answer

Changing The Camera Position & Offsetting LookAt 2 Answers

Get a child object to rotate a parent to the cameras direction -1 Answers

Look at multiple cameras 2 Answers

transform.LookAt not updating each frame until UI Slider input is changed 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