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
1
Question by Fonserbc · Aug 13, 2012 at 06:23 PM · transformquaternionlocalglobal

Transform global quaternion from local quaternion

I'm making a racing game camera.

I have the "Vehicle" wich moves arround and I have a camera following the vehicle. This camera is held by an empty gameObject wich I'll name CameraHolder.

In the Hierarchy the Camera is son of the CameraHolder, wich is son of the Vehicle.

  • Vehicle
    • CameraHolder
      • Camera

The camera is always at the same distance from the CameraHolder and I rotate the cameraHolder using mouse.

 angleX += Input.GetAxis("Mouse X")*sensitivity;
 angleY += Input.GetAxis("Mouse Y")*sensitivity;
 
 var wantedRotation : Quaternion = Quaternion.Euler(-angleY, angleX, 0);

 transform.rotation = toGlobal(wantedRotation);

The problem is that I want angles to be relative to the Vehicle's rotation so I need to transform the local Quaternion wantedRotation generated from angles, to global Quaternion using the Vehicle rotation quaternion in some way.

I need some way of toGlobal() function.

Probably, if it's not possible I'll need to work on Euler Angles or Directions.

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

2 Replies

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

Answer by ScroodgeM · Aug 13, 2012 at 06:26 PM

sol 1

use local rotation directly

 transform.localRotation = wantedRotation;


sol 2

use offset from another object's rotation

 transform.rotation = otherTransform.rotation * wantedRotation;
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 Fonserbc · Aug 13, 2012 at 10:22 PM 0
Share

I used localRotation before but failed, just found that it was my fault for using transform.rotation on my operations to assign to the transform.localRotation later. It works now. Thanks!

avatar image
1

Answer by Meceka · Mar 27, 2020 at 03:53 PM

You can get the global rotation based on the parent objects global rotation and a local rotation like this;

Quaternion worldRotation= transform.parent.rotation * localRotation;

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

10 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

Related Questions

Help with local and world translation.position 0 Answers

Maya objects with different transforms. 1 Answer

use world axis when using transform.rotate 3 Answers

Simulating different gravity, how to make falling platform fall in the desired direction? 1 Answer

Vertex Coordinates to Global Vector3 2 Answers


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