Page 1 of 1

Nuke Code (lua)

Posted: Fri Aug 27, 2010 7:09 pm
by trickser
I tired to find the algorithm which determines nuke movement, but I did not find time and/or interest to finish the research.
Anyway, here is the function I use for the basic nuke path curves.

Code: Select all

function GetNextNukePos (startX,startY,targetX,targetY,curPosX,curPosY)
   local relDist = (distance(curPosX,curPosY,targetX,targetY)/distance(startX,startY,targetX,targetY))
   local angle = math.pi/3*relDist+(math.atan2(targetY-curPosY,targetX-curPosX))
   local speed = ((0.01+0.01*(1-relDist)^2)*GetGameSpeed())
   local nextX = curPosX + math.cos(angle)*speed
   local nextY = curPosY + math.sin(angle)*speed
   return nextX, nextY

where distance is a simple function to calculate the distance of 2 points.