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 alexguerin · Oct 27, 2012 at 11:19 PM · rotationrotatedirection

Rotate but keep direction

I'm having trouble with rotating. The player movesw from one platform to the next and faces the same direction. I thought I had it working fine but it seems platforms with certain rotations do not work.

Moving from A -> B causes him to face back towards A, however, if B = (0,345,0) it works as expected.
Moving from A -> C works
Moving from C -> D causes him to also face back towards C

Basically, I want him to move to the platform infront and take on it's direction but still face in the correct direction.

I've tried several things but all don't work.

 look = Quaternion.LookRotation(transform.forward);  
 targetRotation = hit.transform.rotation * look;


![alt text][1] [1]: /storage/temp/4485-rotate.png

rotate.png (300.8 kB)
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 Phoskryfes · Oct 29, 2012 at 01:50 PM 0
Share

$$anonymous$$aybe showing the script might help them fix it. It's nearly all about scripting.

avatar image Phoskryfes · Oct 29, 2012 at 01:52 PM 0
Share

press the code button at the bottom of the title of the question when you pressed the edit button of your question.

1 Reply

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

Answer by alexguerin · Oct 30, 2012 at 07:22 AM

Okay, I think I've solved it with the below. If the destination's opposite angle is a shorter turn than going to the actual destination, then rotating towards that seems to keep him facing in the correct direction.

 // Figure out which was to turn whilst still maintaining his direction.
 // EG. turning from 0->345 is correct, turning from 0->165 (345's opposite) is closer
 // but doesn't keep his original direction.
 targetRotation = hit.transform.rotation;
 float currentAngle = transform.rotation.eulerAngles.y;
 float destAngle = hit.transform.rotation.eulerAngles.y;
 
 // If the current and destination is rotated by 90 degrees then ignore it and don't rotate.
 // Round the angle since he might be 0.0001 off which is enough to break the MOD.
 float destFloor = Mathf.Floor(destAngle % 90);
 float currentFloor = Mathf.Floor(currentAngle % 90);
 if (currentFloor == 0f && destFloor == 0f)
 {
     targetRotation = transform.rotation;
     return;
 }
 
 // Get the 180 angle of the destination.
 float one80;
 if (destAngle - 180f < 0)
 {
     one80 = destAngle + 180f;
 }
 else
 {
     one80 = destAngle - 180f;
 }
 
 // Calculate the angle between A to B and A to B's 180 and take the shortest.
 float angle2Dest = Mathf.Abs(Mathf.DeltaAngle(currentAngle, destAngle));
 float angle2180 = Mathf.Abs(Mathf.DeltaAngle(currentAngle, one80));
 if (angle2Dest < angle2180)
 {
     targetRotation = targetRotation;
 }
 else
 {
     targetRotation = Quaternion.Euler(new Vector3(targetRotation.eulerAngles.x, one80, targetRotation.eulerAngles.z));
 } 

 
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

How can I move an object to click point in 2D? 0 Answers

Make player move in local direction he is turned. 1 Answer

Rotate a GameObject [set front] 1 Answer

Limiting RotateTowards on two axes 1 Answer

(Picture for Clarity) How do you click on an object, and from that hit point, calculate a direction vector, and then make that direction vector be the upwards direction of an object? 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