Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Motion prediction functions ( ai aiming )

Author
Message
noobnerd
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 2nd Nov 2011 18:18
Ok so i have some motion prediction functions that i thought i might share...

They all have many possible uses, most prominently as smart ai aiming.
also they can be used to :
-aim assist for the player
-drawing trails
and some others

here they are:

first the most advanced one:

where x1#,y1# is the coordinates for the target xv1#,yv1# is the x and y velocity of the target x2#,y2# is the coordinates of the shooter xv2#,yv2# is the x and y velocity of the shooter and v# is the bullet velocity

how to use this function and when?
use this if you use realistic physics where the bullets movement vector becomes the shooters vector+the bullet vector.
for those that dont get this, its like if you run and throw a stone forward, the stones velocity will be you running speed+your throwing speed.

using vectors in your code makes using this command much easier.

the returned value d# is the time in frames before the "impact" will occur. from that we can easily extract the x and y coordinates of the collision :
collisionx# = x1#+xv#*d#
collisiony# = y1#+yv#*d#

and voila, we have the collision xy coordinates.

how did that help?

shooting something from x2#,y2# with the velocity v# in that direction ( angle# = atanfull(collisionx#-x2#,collisiony#-y2#) ) will always result in a hit. ( if the target moves with a constant speed, without changing direction)



the less advanced one.

same as above except that it doesnt take shooter velocity in account. use this one for ex. to platformshooters ( which usually dont need super physics ) or ai turrets ( which dont move )

same variables as above.
also returns d#, see above



and lastly, the pure motion predicting functions:

these two give you the x and y coordinates of a future ( or past ) point in 2D space where a thing moving at a constant speed v# with a constant change in angle a# starting at an angle ca#

where x#/y# is the current location of the thing, ca# is the current angle#, a# is the change in angle per frame, v# is the velocity# and t# is the time in frames.



hope someone finds some use for these.
the 2 first function should be easy to convert to 3D so if someone needs them in 3D u can ask me here

Login to post a reply

Server time is: 2024-03-29 06:34:18
Your offset time is: 2024-03-29 06:34:18