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 GoodArcade · Aug 12, 2013 at 04:51 PM · camerarotationquaternion

Im soo close. How can i tweak my camera's rotation?

 var target:Transform;
 var distance:float = 10.0;
 var height:float = 5.0;
 var smoothTime = 2.5;
   
 function Update () 
 {
     if(!target)
     return;

     currentRot = Quaternion(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
     targetRot = target.rotation;
     
 
     newRot = Quaternion.Lerp(currentRot, targetRot, smoothTime * Time.deltaTime);
     
     transform.rotation = newRot;
     transform.position = target.position - (transform.forward*distance)+(target.up*height);
 }

This is the current script i am using. My player rotates in every axis and this script allows the camera to follow behind the character no matter what rotation. When i attached it to my camera it follows my character perfectly. However, the camera is not angled to face the character directly. All i need to do is somehow tweak the camera's local x rotation so its looking down a tad but i dont know how to go about that with this script. If anyone could help that would be great Thanks c:

I am just so lost when it comes to these:

transform.rotation

transform.eulerAngles

transform.localEulerAngles

Quaternion.Euler

Quaternion.EulerAngles

Quaternion's stupid w value

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 GoodArcade · Aug 12, 2013 at 05:01 PM 0
Share

WooHoo i forgot i could combine rotations using '*='

$$anonymous$$y new script:

function Update () { if(!target) return;

 currentRot = transform.rotation;
 targetRot = target.rotation;
 
 targetRot *= Quaternion.Euler(offset, 0, 0);
 

 newRot = Quaternion.Lerp(currentRot, targetRot, smoothTime * Time.deltaTime);
 
 transform.rotation = newRot;
 transform.position = target.position - (transform.forward*distance)+(target.up*height);

}

1 Reply

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

Answer by robertbu · Aug 12, 2013 at 05:01 PM

One easy way to do this is to make create an empty game object, position the empty game object at the same position as the camera, and then make the camera a child of the empty game object by dragging and dropping on the empty game object in the inspector. The script above goes on the empty game object. You can then rotate your camera a bit on the 'x' axis to create a relative rotation wrt the parent object.

It is unlikely you should ever have to deal with the 'w' in a Quaternion. Line 11 could better be written as:

 currentRot = transform.Rotation;

Depending on where you want the camera to look, and another way to achieve your goal her would be to use Quaternion.LookRotation(). The code for lines 11 and 12 would look like:

 CurrentRot = transform.rotation;
 targetRot = Quaternion.LookRotation(target.position - transform.position, target.up);
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

15 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

Related Questions

Multiple Cars not working 1 Answer

allows users to view 360º content without a VR headset 0 Answers

How to make camera rotation relative to target. 3 Answers

How do I properly rotate an FPS camera with a joystick? 1 Answer

Workaround for Quaternion.eulerAngles 360 Degree Limit? 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