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)

function advaimbot(x1#,y1#,xv1#,yv1#,x2#,y2#,xv2#,yv2#,v#)
m# = x1#-x2# : n# = xv1#-xv2# : o# = y1#-y2# : p# = yv1#-yv2#
m2# = m#^2 : n2# = n#^2 : o2# = o#^2 : p2# = p#^2 : v2# = v#^2
mov# = (m2#+o2#)*v2# : mp# = m2#*p2# : no# = n2#*o2# : mn# = m#*n# : op# = o#*p# : mnop# = 2*mn#*op# : vnp# = v2#-n2#-p2#
sq# = mov#-mp#+mnop#-no# : ex1# = -mn#-op# : ex2# = mn#+op#
if sq# >= 0
q# = sqrt(sq#)
top1# = -q#-ext1# : top2# = q#+ext2#
if vnp# <> 0 then k1# = top1#/vnp# : k2# = top2#/vnp#
if k1# < 0 then k1# = 10000
if k2# < 0 then k2# = 10000
d# = min(k1#,k2#)
ENDIF
ENDFUNCTION d#

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

function aimbot(x1#,y1#,xv#,yv#,x2#,y2#,v#)
v1# = x1#-x2# : v2# = y1#-y2# : v11# = v1#*xv#*2 : v21# = v2#*yv#*2 : v12# = xv#*xv# : v22# = yv#*yv#
v1# = v1#*v1# : v2# = v2#*v2# : v1# = v1#+v2# : v2# = v11#+v21# : v3# = v12#+v22#-(v#*v#)
discr# = v2#*v2#-4*v1#*v3#
if discr# > 0
d1# = 1.0/((-v2#+sqrt(discr#))/(2*v1#)) : d2# = 1.0/((-v2#-sqrt(discr#))/(2*v1#))
if d1# < 0 then d1# = 1000000
if d2# < 0 then d2# = 1000000
d# = min(d1#,d2#)
else
exitfunction 0.0
ENDIF
ENDFUNCTION d#

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.

function xmotionangle(x#,ca#,a#,v#,t#)
r# = (565.4866776*v#)/a# : rx# = newxvalue(x#,ca#+90,r#) : nx# = sin(ca#-90+a#*t#)*r#+rx#
ENDFUNCTION nx#
function ymotionangle(y#,ca#,a#,v#,t#)
r# = (565.4866776*v#)/a# : ry# = newzvalue(y#,ca#+90,r#) : ny# = sin(ca#-90+a#*t#)*r#+ry#
ENDFUNCTION ny#

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