Skip to content

Instantly share code, notes, and snippets.

@wilbefast
Last active August 29, 2015 13:57
Show Gist options
  • Save wilbefast/9752001 to your computer and use it in GitHub Desktop.
Save wilbefast/9752001 to your computer and use it in GitHub Desktop.
Make shiny souls move towards and orbit around the an object.
function Soul:update(dt)
local target_x, target_y = self.target_x, self.target_y
-- do we already have a target?
if (not target_x) and (not target_y) then
-- figure out the hook position
local hook_angle = math.pi*2/(#self.master.souls)*self.index + love.timer.getTime()*3
target_x = self.master.x + math.cos(hook_angle)*32
target_y = self.master.y + math.sin(hook_angle)*32
end
-- pull towards hook
local ddx, ddy = target_x - self.x, target_y - self.y
self.dx = self.dx + ddx*dt*10
self.dy = self.dy + ddy*dt*10
-- on target?
local dist2 = ddx*ddx + ddy*ddy
if self.onTarget and (dist2 < 25) then
self:onTarget()
self.purge = true
else
-- update soul position
GameObject.update(self, dt)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment