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 Pauls · Dec 04, 2012 at 08:18 AM · cameratransformcamera-movement

Change angle of camera: eulerAngle issue

Hi,

in the pre-written script made by Unity, to make the camera follow an object, i would like the angle to not point towards "0" (eulerAngles.y here) but a bit more up, so that the camera is not pointing to the feet of my character.

But i can't find out how to modify this, when i directly change the eulerAngle to a number, it rotates itself around the character from left to right instead of up/down.

Would you know how i could achieve this? (make the camera look a bit up, towards the trunk of the character for example)

Here is the code of the script attached to the camera (ball is the target) :

 // Calculate the current rotation angles
     Debug.Log("ball.eulerAngles.y : "+ball.eulerAngles.y);
     var wantedRotationAngle = ball.eulerAngles.y;/* HERE, if i change the angle, it goes left/right instead of up/down)  */
     var wantedHeight = ball.position.y + height;
 
     var currentRotationAngle = transform.eulerAngles.y;
     var currentHeight = transform.position.y;
 
     // Damp the rotation around the y-axis
     currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
 
     // Damp the height
     currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
 
     // Convert the angle into a rotation
     var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
 
     // Set the position of the camera on the x-z plane to:
     // distance meters behind the ball
     transform.position = ball.position;
     transform.position -= currentRotation * Vector3.forward * distance;
 
     // Set the height of the camera
     transform.position.y = currentHeight;
 
     // Always look at the ball
     transform.LookAt (ball);
     }
 


Thanks

Comment
Add comment · Show 4
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 fafase · Dec 04, 2012 at 08:23 AM 1
Share

You could simply add an empty game object to your guy and make the camera look at it. This way it is even easier to make go up/down or left/right simply modifying the transform of that object. The camera will follow blindly.

avatar image Pauls · Dec 04, 2012 at 12:10 PM 0
Share

@fafase thanks fafase, yes actually you're right, i don't know why it works with an empty, the lookAt points to the correct direction, and not if i let the entire character as the target (in this case it looks at his feet) anyway, it works now, thanks ;-)

avatar image Owen-Reynolds · Dec 04, 2012 at 01:33 PM 1
Share

The script looks at `transform.position`, which is a single point. There's no hidden step where it figures the center of the guy. Characters are usually created with position at the feet, so you can place them on the ground. Standard modelling stuff. Try placing a cube at 0,0,0. You'll see that position is in the center, for them.

Empties work since they have a position, which is all the script cares about.

avatar image Pauls · Dec 05, 2012 at 12:00 AM 0
Share

thanks for the answer !

1 Reply

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

Answer by aldonaletto · Dec 04, 2012 at 03:16 PM

The camera always look at the target pivot, as @OwenReinolds said. A possible solution (as @fafase said) is to child an empty object to the character, adjust its position to where the camera should aim at, and assign it to ball - this way the camera will follow the empty object, not the character.
But there's another solution that would avoid changes in the character: instead of LookAt(ball) use the LookAt(Vector3) variant and define a position a little above the ball:

 var offset: float = 0.5; // vertical distance above ball

 ...
 // Always look at the ball
 var pos = ball.position; // get the ball position...
 pos.y += offset; // shift it vertically...
 transform.LookAt (pos); // and turn the camera to the calculated position
 }
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 Pauls · Dec 05, 2012 at 12:00 AM 0
Share

thanks, great!

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

12 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

Related Questions

Using lerp to go between 3 different locations isn't working 0 Answers

Clamping cameras with different rotation 0 Answers

How to make camera move like it does in the scene viewport? 0 Answers

camera follow obect on pan to z axis 0 Answers

Move camera when mouse is near the edges of the screen 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