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 DayyanSisson · Jul 10, 2012 at 07:08 PM · quaternionaxisslerplocklookrotation

Quaternion LookRotation/Slerp Axis Lock

I've been using this code to rotate an object towards another object:

 var rotate = Quaternion.LookRotation(target.position - AI.position); 
 AI.rotation = Quaternion.Slerp(AI.rotation, rotate, Time.deltaTime * rotateDamp);

Unfortunately this rotates the whole object. I need it to only rotate along the y-axis. How should I lock all the other axis' besides the y-axis to rotate the object? (I've tried using the rigidbody axis constraints).

Thanks in advance.

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

3 Replies

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

Answer by DayyanSisson · Jul 17, 2012 at 02:15 AM

I ended up just using euler angles to lock the x/z axis to 0 and then use the normal rotation code from there.

Comment
Add comment · Show 3 · 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 suttsc · Jul 19, 2012 at 08:30 AM 0
Share

I would be interested in seeing the snippit of code you used as I am trying to solve a similar problem but locking to the z axis. Thanks

avatar image suttsc · Jul 19, 2012 at 09:33 AM 0
Share

I have found a solution to my problem from this page http://forum.unity3d.com/threads/36377-transform.LookAt-or-Quaternion.LookRotation-on-1-axis-only Just mentioning it here for other people to looking for a solution to a similar problem.

avatar image DayyanSisson · Jul 21, 2012 at 08:47 PM 0
Share

Here you go:

 Vector3 eulerAngles = transform.rotation.eulerAngles;
 eulerAngles = new Vector3(0, eulerAngles.y, 0);
 transform.rotation = Quaternion.Euler(eulerAngles);
avatar image
0

Answer by phil · Jul 10, 2012 at 08:45 PM

Use mathf.lerp http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Lerp.html Var rotate = Quaternion.LookRotation(target.position - AI.position); Then put AI.rotation = Mathf.Lerp(AI.rotation.y ,rotate.y, Time.deltaTime * rotateDamp);

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 DayyanSisson · Jul 10, 2012 at 09:24 PM 0
Share

No that wouldn't because $$anonymous$$athf.Lerp returns a float and AI.rotation is a Quaternion. I tried AI.rotation.y = $$anonymous$$athf.Lerp(....); but that gave me a storing a temporary variable error and when I fixed that it started rotating strangely. Its supposed to move between two waypoints (a patrolling movement) but once it reaches one waypoint its supposed to turn to another one. Now it starts turning a little bit, then moves forward, then rotates back to its old rotation, then moves forward a bit more, then rotates back a little bit, etc.... not sure why its doing that.

avatar image
0

Answer by phil · Jul 11, 2012 at 12:25 AM

Try this , Quaternion will need to use W too

pragma strict

var AI : Transform;

var target : Transform;

var rotateDamp : float= 10;

function Update () {

var rotate = Quaternion.LookRotation(target.position - AI.position);

var temp = Quaternion.Slerp(AI.rotation, rotate, Time.deltaTime * rotateDamp);

//AI.rotation.x = temp.x;

AI.rotation.y = temp.y;

//AI.rotation.z = temp.z;

AI.rotation.w = temp.w;

//AI.rotation = temp;

}

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers

Misbehavior with Quaternion.Slerp 3 Answers

Rotate object on one axis with slerp 1 Answer

Quaternion.Slerp with Quaternion.LookRotation causes unexpected results 1 Answer

Slerp to make the right/left side face another object 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