Advertisement
Guest User

Untitled

a guest
May 29th, 2017
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. Vector.Animation.CircularMotion = function(_self,_center,_speed)
  2.   --[[
  3.   CircularMotion takes a position a center and a speed,
  4.   given the position and center, find a vector dif from center to start_vec,
  5.   use the magnitude of dif to find the circle radius, use the angle between the components of dif to find the start location on the circle,
  6.   set the step to the appropriate starting location
  7.   ]]--
  8.   local dif = _center - _self
  9.   local radius,step = Vector.magnitude(dif), atan2(dif.x,dif.y)*framerate/_speed
  10.  
  11.   local function update(_end)
  12.     while not _end do
  13.       step += 1
  14.       _self:Set(-cos((step/framerate)*_speed)*radius + _center.x,-sin((step/framerate)*_speed)*radius + _center.y)
  15.       yield()
  16.     end
  17.   end
  18.  
  19.   return cocreate(update)
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement