what is the formula for Predictive aim ?

Get help using Construct 2

Post » 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
113
S
41
G
20
Posts: 1,586
Reputation: 19,116

Post » 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
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Previous

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 44 guests