Friday, November 16, 2018

game design - who turn a moving agent to the specific coordinate


i have a moving agent in gis map that is going to the special Coordinate . with assumption that maximum angel of rotation is predefined, i want the agent turn into specified coordinate (in moving) and then go to that location, what i do for this work please help me.


enter image description here




Answer



Imagine that you would make a vector from the moving agent straight to the target location. Instead of using this new vector as your agent's path, you can update you path slightly every iteration with your angle rotation you mentioned, so that it eventually starts going straight to the location.


Algoritm in steps:



  1. Make a vector from agent to target location

  2. Check which direction gives the smallest angle to rotate to face the target location


  3. Check to see if this angle is below (for example) 10 degrees.


    4a. If it is, simply set the path to the vector you made in step one (to avoid zig-zagging)


    4b. If not, rotate your initial path-vector in this direction with your angle rotation speed.





Granted that your rotation speed is low enough, this will make the agent take a smoother path towards the target location.


Depending on what framework you are working in, a "slerp" or "lerp" function might already be implemented which is very useful!


http://answers.unity3d.com/questions/13869/how-do-i-get-smooth-rotation-to-a-point-in-space.html


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...