what is the formula for Predictive aim ?

Get help using Construct 2

» Tue Aug 25, 2015 1:48 am

@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:

Code: Select all
`function aimAngle(turret, target, bulletSpeed) {    var adjustedX = target.x - turret.x;    var adjustedY = target.y - turret.y;    var rCrossV = adjustedX * target.vy - adjustedY * target.vx;    var magR = Math.sqrt(adjustedX^2 + adjustedY^2);    var angleAdjust = Math.asin(rCrossV / (bulletSpeed * magR));    return angleAdjust + Angle(turret.x, turret.y, target.x, target.y);}NOTE: adjustedX^2 == adjustedX * adjustedX, ^ is the power operator.`
Moderator
B
114
S
41
G
20
Posts: 1,586
Reputation: 19,161

» Tue Aug 25, 2015 2:27 am

@linkman2004 ahh very nice.. works like a charm!

thanks, I needed this formula and I couldn't use the turret behavior for what I am doing... thanks again!
B
103
S
35
G
16
Posts: 1,224
Reputation: 17,192

Previous