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 TazmanNZL · Nov 18, 2021 at 01:05 AM · rotation3dangles

Vector3.SignedAngle angle not changing when object rotates

I'm trying to rotate towards an object whilst applying some roll on the Z axis. I'm doing something wrong because the Angle never changes even when my object is rotated to face the target. If I move the target object it does change but if I move the object I am rotating it doesn't change.. I'm wanting anything on the left of forward Z to be -degrees and anything on the right of it to be +degrees.. So I'm expecting the angle to change as the object turns to face the target.. Update method below..

 Vector3 direction = target.position - transform.position;
         Vector3 dirTo = transform.up;
 
         float angle = Vector3.SignedAngle(direction, dirTo, transform.forward);
 
         float angleOffsetZ = angle * -0.2f;
 
         Quaternion rot = Quaternion.LookRotation(target.position);
 
         Quaternion rotZ = Quaternion.Euler(1,1, angleOffsetZ);
 
         Quaternion combinedAngle = rot * rotZ;
 
         transform.rotation = Quaternion.Slerp(transform.rotation, combinedAngle, 0.7f * Time.deltaTime);
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 TazmanNZL · Nov 19, 2021 at 09:08 PM

So I figured out that angles in Unity are not so straight forward. Vector3.right is zero degrees and anything in a circle from that is always positive. So I ended up using Vector3.angle instead and using the object forward. I'm not using Physics or a NavAgent and am moving a spaceship to a target. When the ship turns to face the target I am applying some rotation on the Z axis to make it look like the ship is banking in the turn. Problem I have is getting it to roll in the right direction when turning. Sometimes it banks left when making a right turn which looks weird. Here is what I now have. Any advice or correction in my logic would be appreciated.. Here is my new Update method..

 Vector3 direction = target.position - transform.position;
 
 float angle = Vector3.Angle(direction , transform.forward);
 
 Quaternion rot = Quaternion.LookRotation(direction);
 Quaternion angleAxis = new Quaternion();
 
 float angle2 = transform.localEulerAngles;
 
 if (transform.position.x > oldXPos && angle2.y > 100f) {
             angleAxis = Quaternion.AngleAxis(angle * -0.35f, Vector3.forward);
         }
 else if (transform.position.x < oldXPos) {
             angleAxis = Quaternion.AngleAxis(angle * 0.35f, Vector3.forward);
         }
 
 Quaternion combined = rot * angleAxis;
 
 transform.rotation = Quaternion.Slerp(transform.rotation, combined, Time.deltaTime);
 transform.position += transform.forward * speed * 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 TazmanNZL · Nov 21, 2021 at 12:20 AM 0
Share

So turns out I was trying to do things the hard way and what I have figured out is that I can use: Vector3 shipRelative = transform.InverseTransformPoint(target.position);

This will tell me if the target is left of my ship or right of my ship.. Only took me several hours to figure this out.. sheesh..

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

209 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Aplying all 3 axes on object like in inspector causes gimbal lock (different from other rotation problems),Rotate all angles of an Object to an specific angle cause gimbal lock 1 Answer

Determine degrees rotated around an arbitrary axis 0 Answers

change direction by rotating object around y axis and adding relative torque 1 Answer

Rotation Question in Top-down 3D Game 0 Answers

Limiting the rotation of an object 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