AiController = {} AiController.__index = AiController function AiController:new(controlling) return setmetatable({ controlling = controlling, time = 0 }, AiController) end function AiController:follow(target) self.target = target end function AiController:update(dt) if self.target ~= nil and not self.target.knockback then diff = self.target.position - self.controlling.position self.controlling.velocity = diff:normal() * 20 self.controlling:transition_to(States.Walk) end self.time += dt if self.time >= 5 then self:shoot() self.time = 0 end end function gliding_gun() _glider_damage = { amount = 2, knockback = { magnitude = 300, time = 0.070 } } GlidingGunBuilder = EntityBuilder:new(World) function GlidingGunBuilder:transition_state() end return GlidingGunBuilder:b_type(Entities.Bullet) :b_line_of_sight(vec2(1, 0)) :b_position(vec2(100, 100)) :b_health() :b_render_order(0) :b_collidable() :b_live_for(2) :b_velocity(vec2(-40, 0)) :b_collision_bounds(vec2(3, 4), vec2(5, 6)) :b_add_state( States.Active, { animation = { pos_y = { sequence = { 75, 76, 77, 78 }, dt = 0.10 }, neg_y = { sequence = { 75, 76, 77, 78 }, dt = 0.10, reflect = vec2(true, true) }, pos_x = { sequence = { 75, 76, 77, 78 }, dt = 0.10 }, neg_x = { sequence = { 75, 76, 77, 78 }, dt = 0.10, reflect = vec2(true, true) } } } ) :b_damage(_glider_damage) :b_state(States.Active) :build() end function AiController:shoot() diff = (self.target.position - self.controlling.position):normal() * 50 a, b, c = gliding_gun(), gliding_gun(), gliding_gun() a.position = vec2(self.controlling.position) a.velocity = diff:clockwise_rotate(-0.05) b.position = vec2(self.controlling.position) b.velocity = diff:clockwise_rotate(0.05) c.position = vec2(self.controlling.position) c.velocity = diff end