local heav_object_2 = {hitbox = 4} local obj = require "obj" local debug_arrow = require "debug_arrow" function heav_object_2:draw() set_color(0.8,0.7,0.95) line(-4, -4, -4, 4, 4, 4, -4, -4) line(3, -3, -3, -3) line(3, -3, 3, 3) line(4, 4, 4, -4, -4, -4) end function heav_object_2:init() end function heav_object_2:tick() local x, y = self.data.pos[1], self.data.pos[2] local vx, vy = self.data.vel[1], self.data.vel[2] for obj in obj.in_circle(x, y, 40) do if obj ~= self then local ox, oy = obj.data.pos[1], obj.data.pos[2] local ovx, ovy = obj.data.vel[1], obj.data.vel[2] -- shift frame of reference ox = ox - x oy = oy - y ovx = ovx - vx ovy = ovy - vy local mag = math.sqrt(ovx^2 + ovy^2) ovx = ovx * 0.99 ovy = ovy * 0.99 local diff = math.sqrt(ovx^2 + ovy^2) - mag self.data.avel = self.data.avel + diff * (self.data.avel > 0 and 1 or -1) ovx = ovx + vx ovy = ovy + vy obj.data.vel[1] = ovx obj.data.vel[2] = ovy end end end return {heav_object_2 = heav_object_2}