Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GTHell · Apr 30, 2017 at 04:08 PM · camerascript.maththird-person-camera

Could anyone explain me this ThirdPerson camera Script?

 void LateUpdate(){
         Vector3 direction = new Vector3 (0, 0, -distance);
         Quaternion rotation = Quaternion.Euler (inputY, inputX, 0);
         camTransform.position = playerObj.position + rotation * direction;
         camTransform.LookAt (playerObj.position);
     }

This script attach to main Camera. I get this script from some place but couldn't understand the: playerObj.position + rotation * direction; . It's like a math kind of thing to me. I just need an explanation to why the position + the rotation equal to some kind of expand circle? Is there any math subject I could take a look at?

Comment
Add comment · Show 2
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 toddisarockstar · Apr 30, 2017 at 05:01 PM 0
Share

looks kinda wonky to me. Why don't you just describe exactly what you're trying to make the camera do and we can help. Are you just wanting the camera to slowly follow the player? or if you simply want the camera fixed behind the player you dont need script, you just make it a child object in the inspector.

avatar image GTHell toddisarockstar · May 08, 2017 at 01:37 AM 0
Share

I'm not asking for help on code. I just want to understand the code by not being a cargo-cult programmer. Understanding this could open a lot of possibilities to customize and unlock my new skills. Without understanding this, The only type of Camera I could get is the same as GTA but with understanding how it work I could turn it into many cool combination of Camera.

And make child object of Camera seem unprofessional because it's not customization and ...Performance.

1 Reply

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

Answer by Glurth · Apr 30, 2017 at 05:39 PM

ok, the order of operation is important here

playerObj.position + rotation * direction ..... is equivilent to

playerObj.position + (rotation * direction) which makes it slightly clearer what's happening..

inside the parens we are multiplying a Vector3 (direction and magnitude) with a Quaternion (an orientation/rotation) When you multiply these together, like that, you are "rotating the vector, by the quaternion" https://docs.unity3d.com/ScriptReference/Quaternion-operator_multiply.html (second half) The resultant vector will have the same magnitude as the original, but its direction will be altered.

The last step is simply Vector3 addition: adding the rotatedDirection to your position. This will generate a point that is offset from your position by the magnitude of the rotatedDirection, in the direction defined by the rotatedDirection Vector3 https://docs.unity3d.com/ScriptReference/Vector3-operator_add.html.

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 GTHell · May 01, 2017 at 05:53 PM 0
Share

Can you explain more a bout "rotating the vector, by quaternion"? It's a bit hard to grasp what you've said.

avatar image Glurth GTHell · May 01, 2017 at 06:38 PM 2
Share

The details of how exactly quaternion work is rather complex, but their use is much easier. A Queternion specifies a particular rotation/orientation in 3d space. A Vector3, on the other hand, describes a location (or equivalently, a direction and magnitude) in 3d space.

Let's say as an example, you have a Vector3 that defines a position (1,0,0). And your Quaternion is a 90 degree rotation clock-wise about the Y axis.

When we multiply these two together ("rotating the vector, by quaternion"), the 3d point (1,0,0) gets spun about the Y axis (which passes through the origin at 0,0,0 ) by 90 degrees. The resultant vector in this simple case will be (0,0,1).

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

96 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Check if camera have a post-profile 0 Answers

How do you change the values of Vector3 Offset (x, y, z) in script randomly/overtime? 0 Answers

Rotating camera around the sphere 2 Answers

Convert screenspace coordinates (top-left origin) to worldspace coordinates. Read before you react! 1 Answer

What is the difference between gameobject movement speed by velocity and calculating the speed with deltatime and magnitude ? 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