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 cheliotK · May 16, 2013 at 08:51 PM · timenavmeshagentspeed

Question about navMeshAgent speed and the "Time" variable

I get a weird outcome when i try to program my navMeshAgent's speed. I want it to arrive at the target at a specific time, but somehow it manages to arrive earlier. (Although that's not so bad, since I'm modelling bus routes, it's nice for the bus to arrive early!)

To be more specific, lets say I have 2 gameObjects, target1 and target2. When the agent reaches target1, it gets a new destination, target2. target1 has a variable in a script called target1atts.js that's attached to it, containing only the line:

 var arrTime = 10.0   // arrival time for target 1

Likewise, target2 has the target2atts.js script attached, containing:

 var arrTime = 30.0   // arrival time for target 2

Furthermore, using the NavMeshAgent.CalculatePath function, I know the path length between the 2 targets is 420. (Quick question here, what units is this length in?) In a script attached to the navMeshAgent, I have the following:

 var depTime = 10.0                  //the time the agent arrived at target1
 var arrTime = 30.0                  //the time the agent needs to arrive at target2
 var tripDuration = arrTime - depTime
 var pathLength = 420                //taken from NavMeshAgent.CalculatePath
 var spd = pathLength/tripDuration   //effectively the speed for this trip, equals 21
 agent.speed = spd

Given that the navMeshAgent is at target1 when Time.time equals 10 (give or take some ms), it should follow that with the above calculations, it would reach target2 when Time.time equals 30 (give or take the same amount of ms). However, it consistently arrives at target2 at around 23 seconds. I would expect it to arrive later than the predetermined time, due to deceleration during turns, but in no way it should arrive earlier, or even that earlier.

I'm stumped, any clues as to what's wrong? I'm almost ready to hold a maths book against the screen, screaming "The power of math compels you!"

Thank you for any insight.

Comment
Add comment · Show 4
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 Fattie · May 16, 2013 at 08:53 PM 0
Share

"Quick question here, what units is this length in?"

You should really always, always, always use meters and $$anonymous$$G in game development. Humanoids must be actually 1.8m high, cars should be actually 3.2n long and weigh 1700kg, and so on.

If your modelmakers send something over "hey just change the scale by 17.42 dude" email right back "hey just build it properly and we'll hey pay you" :-) (Also of course, every single item must be z-forward.)

So anyways meters, yeah

avatar image Fattie · May 16, 2013 at 09:00 PM 0
Share

just BTW 21 m/s is totally wrong for humanoid locomotion, so something's screwed.

(You can always easily remember the top running speed for humans, by just thinking of Usain Bolt's performance .. so, only a handful of humans can reach 10 m/s.)

{Naturally if you're a video game programmer, you don't have to 'remember" that, it would be like remembering how many fingers you have, but I supply that information for new readers! Heh!! :) }

avatar image cheliotK · May 16, 2013 at 09:26 PM 0
Share

Hey Fattie, thanks for the quick answer!

It's good to know that it's up to me to define the correct units in Unity. I'm using an urban scene imported from cityEngine, and with the default First Person Controllers that I've tested it with everything is in the correct scale, but I'll have another look at it, just in case.

As to your second comment, the agent is actually a bus, and the targets are bus stops. Sooooo, 21 m/s would not be THAT crazy. (O$$anonymous$$, only if my bus was starring in "SPEED", but still 75 kph is not extraordinary). Furthermore, both the locations and the arrival times were put at random, as this is more of a proof-of-concept project. For other trips for example, the calculated speed goes up to 30 m/s. So, I'm not judging any results on the actual numbers yet, just the concept.

avatar image cheliotK · May 17, 2013 at 12:19 PM 0
Share

Oh silly me...

I was calculating the total path length from one target to another using this code:

 function calculatePathLength(){
         var path: Nav$$anonymous$$eshPath = Nav$$anonymous$$eshPath();
         agent.CalculatePath(targ.transform.position, path);
         Debug.Log("next path segments: " + path.corners.length);       
         var pathElements = path.corners.length;
         for(i=1;i<pathElements;++i)
         {
             pathLength += $$anonymous$$athf.Abs(Vector3.Distance(path.corners[i-1], path.corners[i]));
         }
 }

The problem is, I never actually cleared the pathLength variable between different targets, in essence looking at the total distance travelled since time 0. Simpy adding

 pathLength = 0.0;

at the start of the function made it work like a charm.

Silly, silly me..

1 Reply

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

Answer by Fattie · May 16, 2013 at 08:55 PM

OK first try your experiment with a straight path .. no turns. See what happens.

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 cheliotK · May 16, 2013 at 09:29 PM 0
Share

Sounds reasonable enough.. Unfortunately the project is at the work computer, I'll try it tomorrow and update accordingly. Thanks

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

14 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

Related Questions

how to slow down speed increase? 2 Answers

[Solved] Reverse animation help 2 Answers

RPG Action Progress Bar always same speed 1 Answer

NavMeshAgents with same variables acting differently 1 Answer

Unity Time.timeScale is out of range. Any chance to set it to 360? 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