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 Steven-1 · May 09, 2012 at 10:12 AM · camerarotationtransformlocalrotation

Issue with transform rotations and local rotations

I got a slightly complex cameras-player setup, which I'll try to explain:

OuterSpaceCam: renders first, renders outher space (low poly), sort of a 3d skybox the OuterSpaceCam is a child of a transform.

SceneCam: renders 2nd, renders the normal scene the SceneCam is a child of the player (character controller), the SceneCam locally only rotates up and down (though I don't think that really matters for this).

OuterSpaceCam.localRotation should always be equal to SceneCam.rotation (this is done on purpose, I actually rotate the OuterSpaceCam.parent so that these rotations are equal, it's OuterSpaceCam.parent only purpose.) I do OuterSpaceCam.localRotation = SceneCam .rotation; every lateupdate. so that the space cam moves correctly with SceneCam which is controlled by the player.

anway, when I go from planet to planet, I want the local scene upaxis to be away from the planet, so in the outer space scene it matches the normal of the position on the surface of the planet I'm on. So I have to rotate both the player and OuterSpaceCam.parent (withouth OuterSpaceCam itself).

So I do this (in the OuterSpaceCam) and that works:

     var CamRotation = transform.rotation;
     transform.parent.LookAt(transform.parent.position+transform.parent.forward,planetNormal);
     transform.parent.LookAt(transform.parent.position+transform.parent.right,planetNormal); 
     transform.parent.LookAt(transform.parent.position-transform.parent.right,hit.normal);
     transform.rotation = CamRotation; //tot hier is het allesinds juist

That makes the OuterSpaceCam.parent rotate so it should be correct, and keeps the OuterSpaceCam.rotation intact so the camera is still correctly orientated.

now I used to do this which rotates the SceneCam:

 rotationTarget.GetComponent<MouseLook>().LockCamera(transform.localRotation);

that works, but I want to rotate the player instead of the SceneCam, I actually want the SceneCam localRotation to stay intact. So I do this, but it doesn't work:

 rotationTarget.parent.rotation = transform.localRotation;
 rotationTarget.parent.RotateAround(rotationTarget.parent.right, 90); //cause the SceneCam has a localRotation of Quaternion.Euler(-90, 0, 0)


So, anyone who understands what I'm saying, and sees what's wrong ? (My god, this must the worst understandable question I've ever asked)

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

1 Reply

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

Answer by Steven-1 · May 09, 2012 at 10:42 AM

ok, so I replaced

 rotationTarget.parent.rotation = transform.localRotation;
 rotationTarget.parent.RotateAround(rotationTarget.parent.right, 90); //cause the SceneCam has a localRotation of Quaternion.Euler(-90, 0, 0)

with

 rotationTarget.parent.rotation = transform.localRotation * Quaternion.Inverse(rotationTarget.localRotation);

and now it works perfectly (or so it seems)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion Slerp Sanity Check 1 Answer

transform.localRotation resets after rotation 1 Answer

is there any possible to use two transform.rotate function for same gameobject?? 2 Answers

Why are localRotation and rotation the same 1 Answer

2D Camera Rotation Along Level Boundaries 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