# what is the formula for Predictive aim ?

1 favourites
• 12 posts
• hi

i can not use turret behavior so i made my own turret system ...

but i need for Predictive aim system

what is the formula ?

i have variables like :

• projectile speed
• turret and target position and angle

and i know my target moving or not

...

thanks

• Hope this helps:

``````function aimAngle(target, bulletSpeed) {
var rCrossV = target.x * target.vy - target.y * target.vx;
var magR = Math.sqrt(target.x*target.x + target.y*target.y);
var angleAdjust = Math.asin(rCrossV / (bulletSpeed * magR));

}[/code:ypau5ukx]

At this link is an even more detailed formula:
• Hope this helps:

``````function aimAngle(target, bulletSpeed) {
var rCrossV = target.x * target.vy - target.y * target.vx;
var magR = Math.sqrt(target.x*target.x + target.y*target.y);
var angleAdjust = Math.asin(rCrossV / (bulletSpeed * magR));

}[/code:1lcl92kw]
``````

thanks ..

but what is "target.vy and target.vx" ?

and construct 2 dont have atan2 ... (i think i must use "angle" but how ?!)

• I edited my post above with an formula that is language independent, I just googled the formula for you

• I edited my post above with an formula that is language independent, I just googled the formula for you

thanks .. but i know that .. i whant the formula in construct 2 ...

if anyone can change the formula to construct 2 please do it .. ?

• It seems to be (i'm not sure):

target.vy = y-coordinate of target after 1 frame (minimal game graphic update)

magR = distance beetween turret and target.

• Vx and vy are the x and y velocities of the target.

Instead of atan2(y,x) you can use angle(0,0,x,y)

• Vx and vy are the x and y velocities of the target.

Instead of atan2(y,x) you can use angle(0,0,x,y)

how do i calculate Vx and vy ?

i still looking for formula ...

• Depending on what movement behavior the target uses they can have an expresion to get velocityX and velocityY, or Speed and angleOfMotion. You can convert the latter to vx,vy with:

vx = speed * cos(angleOfMotion)

vy = speed * sin(angleOfMotion)

• R0J0hound trying to get predictive aim working, but it's not...what am I doing wrong?

https://dl.dropboxusercontent.com/u/362 ... t_aim.capx

• jobel The original formula given here is assuming the turret is situated at (0, 0), so you need a modified formula that takes into account the turret's position. Here's a modified formula:

``````function aimAngle(turret, target, bulletSpeed) {
var adjustedX = target.x - turret.x;
var adjustedY = target.y - turret.y;
var angleAdjust = Math.asin(rCrossV / (bulletSpeed * magR));

return angleAdjust + Angle(turret.x, turret.y, target.x, target.y);
}