for i=1,enemyGroup.numChildren do enemyGroup[i].x = enemyGroup[i].x + (enemyGroup[i].previousEnemyX - shipx) \* 0.3 enemyGroup[i].previousEnemyX = ships end
I run this code every frame to move my enemy ships in my game based on the movement of the player. I recently implemented the enemy ships “flying” on a bezier curve:
local function translate (object, vx, vy, time, ease) local t = 0 local curve = bezier:curve(vx, vy) local proxy = setmetatable({}, { \_\_index = function() return t end, \_\_newindex = function(\_, \_, v) t = v tempx, tempy = curve(t) object.rotation = angleBetween( object.x, object.y, tempx, tempy ) object.x, object.y = curve(t) end}) return transition.to(proxy, {t = 1, time = time, transition = ease}) end
with a transition.to call and use this code:
local function angleBetween( srcX, srcY, dstX, dstY ) local angle = ( math.deg( math.atan2( dstY-srcY, dstX-srcX ) )+90 ) return angle % 360 end
to make the ship face the direction it is flying.
The issue is that the enemy ships freak out and get all kinds of jittery rotation while they are both flying and I move the player’s ship. Does anyone know what might be going on here?