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 gameplay4all · May 10, 2013 at 11:06 AM · rotationquaternionaxisfacingsubtracting

how can i substract one axis by 180?

i have a script that rotates the character to the camera's Y angle but my character's face points to the camera instead of his back. i want to do it like this : this.transform.rotation = Quaternion.Slerp(this.transform.rotation,CameraController.rot/* minus 180*/) ,rotateSpeed * Time.deltaTime);

hope someone can help me :)

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 Fattie · May 10, 2013 at 12:58 PM 0
Share

it's very unlikely you should use quaternions for any reason. Did you try LookAt ?

Did you try .Rotate ?

it could be as simple as .Rotate(0,180,0);

avatar image gameplay4all · May 10, 2013 at 01:04 PM 0
Share

tried this: this.transform.rotation = Quaternion.Slerp(this.transform.rotation,CameraController.rot,rotateSpeed * Time.deltaTime); this.transform.rotate(Vector3(0,180,0)); got an error: $$anonymous$$issing$$anonymous$$ethodExeption

any ideas?

2 Replies

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

Answer by robertbu · May 10, 2013 at 02:11 PM

In some ways your question is puzzling. Assuming you've modeled your character so that the front is looking at positive 'Z', rotating on the 'Y' by 180 with respect to the camera will have your character facing the camera. But no matter what you want, using angles may result in unanticipated rotations since there are multiple eulerAngle representing the same 'physical' rotation. Instead, look at using Quaternion.LookRotation(). So I'm going to assume you have a standard setup with the character running around on the XZ plane and 'Y' is up. And you want to match the character to only the 'Y' rotation of the camera. So get the forward vector of the camera and bring it down to the level of your character:

 var v3 = Camara.main.transform.forward;
 v3.y = transform.forward;
 Quaternion q = Quaternion.LookRotation(v3);
 Quaternion.Slerp(transform.rotation,q,rotateSpeed * Time.deltaTime); 

And if you really do want it 180 degrees from the camera rotaiton, use 'back' (-forward) for your vector.

 var v3 = -Camara.main.transform.forward;
 v3.y = transform.forward;
 Quaternion q = Quaternion.LookRotation(v3);
 Quaternion.Slerp(transform.rotation,q,rotateSpeed * Time.deltaTime); 


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 gameplay4all · May 10, 2013 at 02:14 PM 0
Share

thanks! . .

avatar image
0

Answer by SubatomicHero · May 10, 2013 at 12:21 PM

I think it's as simple as either dividing by 2 or multiplying by 0.5...maybe

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 gameplay4all · May 10, 2013 at 12:41 PM 0
Share

i think i haven't formulated my question right.. i want to make my character face the opposite of the CameraController.Rot like you can use -transform.up or the same transform.up -180 hope this can get you an idea

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

14 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

Related Questions

90 Degree stopping rotation on y-axis issue 0 Answers

"Free" rotation about a sphere 0 Answers

Quaternion.LookRotation only on Y axis 0 Answers

Quaternion Rotation around Local Axis 2 Answers

Rotation to align between two vectors but with preserved Camera Z axis 0 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