• 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
Question by EvilTak · Dec 16, 2014 at 01:17 PM · aisteeringvehicles

Most Efficient Method for Steering for Vehicle AI

Hi Unity Community!

Any tutorial regarding vehicle AI gives the following code for getting the steering magnitude (-1 to 1) to the next waypoint:

 Vector3 pos = transform.InverseTransformPoint(nextWaypoint.position);
 steerMagnitude = pos.x / pos.magnitude;

But since this involves the Sqrt operation, is there a more efficient method? Because I plan on having about minimum 50 vehicles in the scene at a time. But that can even increase to 100 - 200 vehicles. Or is the Sqrt operation fast enough for mobile devices to cope with 200 vehicles using this code each FixedUpdate? I also have other code like OA, etc.

Comment

People who like this

0 Show 3
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 Owen-Reynolds · Dec 16, 2014 at 04:12 PM 0
Share

That formula looks wrong. All it says is to crank the steering wheel linearly based on angle to the target. I assume this needs to run every frame, so you even out eventually. It might work (almost anything will) but it isn't how people drive.

For real, you try to aim at the target as quickly as possible -- if a target is only a little to the right, you still make a "standard turn," and only even out the wheel as you face it.

avatar image EvilTak · Dec 20, 2014 at 05:21 AM 0
Share

So I devised a simple but effective formula (since the current steer magnitude formula returns steering magnitude if the steerAngle was 90 degrees. So I just used the unitary method xD:

 steerMagnitude = pos.x / pos.magnitude * 90 / steerAngle;
avatar image EvilTak EvilTak · Jul 11, 2016 at 07:39 AM 0
Share

Shameless bump, but looking at this question, I realised what kind of a noob I was almost 2 years ago!

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by tanoshimi · Dec 16, 2014 at 02:15 PM

What's your fixed timestep? I think the default is 0.02, but there's no way when I'm driving I adjust by steering 50 times a second.... if you need to keep the timestep that high for other calculations, then don't recalculate the steering magnitude in every FixedUpdate() - put it in a coroutine, say, that runs less frequently.

Comment

People who like this

0 Show 2 · 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 EvilTak · Dec 16, 2014 at 02:32 PM 0
Share

That's a good idea. I'll try that later. Is there any limit for the number of coroutines running simultaneously? Do a lot of coroutines running together have an impact on performance? Since I have a lot of coroutines running forever (but waiting for few seconds after two-three statements) in my other code also.

avatar image tanoshimi · Dec 16, 2014 at 04:18 PM 1
Share

Coroutines don't run "together" - they still run on the main thread, but since they remember their internal state and resume from where they got to after each yield, they allow you to spread calculations over several frames.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

NPCs random movement 2 Answers

Turning an object towards point 0 Answers

Determining rotation for collision avoidance? 3 Answers

makeing enemies 1 Answer

car movement and steering AI algorithms 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