Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 greyhoundgames · Feb 28, 2017 at 07:50 PM · rotationaiming

RotateTowards seems to have non smooth steps

I have the following code which takes 2 objects in the game and finds the vector from A to B and then rotates the forward angle of A towards B. This works well but it appears to have non smooth calculation. For example if I grab object B and slide it slowly, the computed angle to look at does not move until enough distance has gone by and then it jumps to the exact right angle. So its kind of like its unable to do fine grained float calculations. Anyone know what I am doing wrong? Note I am only posting the part that exhibits the error, Debuging out the output vector shows the symptom which is the output stays fixed at the same value until enough distance has changed and then it jumps to the next correct value.

             Vector3 leadPosition = target.position;
             float distance = Vector3.Distance(leadPosition, transform.position);
             Vector3 targetDir = leadPosition - transform.position;
             float step = turnSpeed * Time.fixedDeltaTime;
             Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);


Example output, while things are at rest its printing this

target dir=1.045,128.3109,13.74569 newDir=0.009199157,0.9942687,0.1065141 Then I slide the target along the x axis and you can see the target dir updates but the newDir does not target dir=1.18,128.3109,13.74569 newDir=0.009199157,0.9942687,0.1065141 Then I keep sliding it a bit more until it "clicks" and updates the output angle target dir=1.768,128.3109,13.74569 newDir=0.01368735,0.9942176,0.1065086

Comment
Add comment · Show 1
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 greyhoundgames · Feb 28, 2017 at 07:51 PM 0
Share

Note messing with the step variable seems to have no effect(which makes sense). Also normalizing the distance vector doesn't make a difference either.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by greyhoundgames · Mar 02, 2017 at 07:06 AM

I forced the last parameter to 1 after seeing that in somebody's example and it solved this problem. The unity doc:https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html says to use 0. That may be a mistake.

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

76 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

Related Questions

Rotate my torso in vertical axis towards crosshair (target) 0 Answers

Align the center of Camera towards a position in the world 2 Answers

Rifle Accuracy w/ Rotation 3 Answers

How to rotate car without using transform 0 Answers

Turret aiming script needs adjustment / fine tuning 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