Title says it all. I want to make an NPC circle it’s target. I’ve already taken care of how the NPC can distance itself from a target, but I don’t know where i’d start with making it circle an enemy like a shark.
Visual examples
Title says it all. I want to make an NPC circle it’s target. I’ve already taken care of how the NPC can distance itself from a target, but I don’t know where i’d start with making it circle an enemy like a shark.
Visual examples
if an object’s velocity is always adjusted to be perpendicular to a point, it will follow a circular path about a point.
TargetPos-attackerPosvector2 because it is a 2d problemYou may wish to tighten the circle if the length of the vector found in step 1 is too long. In this case you can use a lerp changing the forward velocity to point more toward the center point by adjusting the alpha parameter.
What pathfinding are you using for the distancing? You could do something like:
count = 0
repeat
count += 1 -- change this to how many degrees apart the waypoints will be around the circle
local direction = target.Position - attacker.Position
local distance = direction.Magnitude
pos = Vector3.new(math.sin(math.rad(count)) * distance, 0, math.cos(math.rad(count)) * distance) + target.Position
-- in here make the attacker walk to pos and a wait until they get there to continue the loop
until false