# what is the formula for Predictive aim ?

Get help using Construct 2

### » Mon Sep 15, 2014 10:46 am

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
B
17
S
6
Posts: 246
Reputation: 1,786

### » Mon Sep 15, 2014 11:00 am

Hope this helps:

Code: Select all
`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));    return angleAdjust + Math.atan2(target.y, target.x);}`

At this link is an even more detailed formula:
http://www.reddit.com/r/gamedev/comment ... la/c7vbu2j
B
44
S
10
G
8
Posts: 437
Reputation: 6,483

### » Mon Sep 15, 2014 11:06 am

Ubivis wrote:Hope this helps:

Code: Select all
`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));    return angleAdjust + Math.atan2(target.y, target.x);}`

thanks ..
but what is "target.vy and target.vx" ?
and construct 2 dont have atan2 ... (i think i must use "angle" but how ?!)
B
17
S
6
Posts: 246
Reputation: 1,786

### » Mon Sep 15, 2014 11:11 am

I edited my post above with an formula that is language independent, I just googled the formula for you
B
44
S
10
G
8
Posts: 437
Reputation: 6,483

### » Mon Sep 15, 2014 11:37 am

Ubivis wrote: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 .. ?
B
17
S
6
Posts: 246
Reputation: 1,786

### » Mon Sep 15, 2014 1:45 pm

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.
B
5
S
1
Posts: 31
Reputation: 441

### » Mon Sep 15, 2014 3:26 pm

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)
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Tue Sep 16, 2014 7:21 am

R0J0hound wrote: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 ...
B
17
S
6
Posts: 246
Reputation: 1,786

### » Tue Sep 16, 2014 3:50 pm

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)
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Tue Aug 25, 2015 12:48 am

@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
B
103
S
35
G
16
Posts: 1,237
Reputation: 17,224

Next