local accelLimit = 300 * 2 -- same as the player, yes? local velLimit = 600 -- same as player Enemy = Tile:extend { image = 'data/enemy.png', maxVelocity = {x=velLimit,y=velLimit}, minVelocity = {x=-velLimit, y=-velLimit}, onUpdate = function(self) -- find where player is relative to us local dx = the.player.x - self.x local dy = the.player.y - self.y local ax, ay = dx, dy if math.abs(dx) > math.abs(accelLimit) then ax = accelLimit * util.signOf(dx) ay = accelLimit * math.abs(dx) / dy elseif math.abs(dy) > math.abs(accelLimit) then ay = accelLimit * util.signOf(dy) ax = accelLimit * math.abs(dy) / dx end self.acceleration.x = ax self.acceleration.y = ay self.rotation = math.atan2(self.velocity.y, self.velocity.x) end }