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 :
and i know my target moving or not
...
thanks
Develop games in your browser. Powerful, performant & highly capable.
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)); return angleAdjust + Math.atan2(target.y, target.x); }[/code:ypau5ukx] At this link is an even more detailed formula: [url=http://www.reddit.com/r/gamedev/comments/16ceki/turret_aiming_formula/c7vbu2j]http://www.reddit.com/r/gamedev/comment ... la/c7vbu2j[/url]
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)); return angleAdjust + Math.atan2(target.y, target.x); }[/code:1lcl92kw]
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); }[/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
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 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.[/code:29wly5il]
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!