Im having a little trouble getting my ai to create a path where it circles around the player, but I have no idea where to start. I tried doing it myself but I have no idea how to use angles or anything like that.
local function createPath(target)
local tHRP = target:FindFirstChild("HumanoidRootPart")
local tPos = tHRP.Position
local path = pfs:CreatePath()
path:ComputeAsync(hrp.Position,tPos)
local waypoints = path:GetWaypoints()
for i, wp in pairs(waypoints) do
local dist = math.abs(math.floor((hrp.Position-tPos).Magnitude))
if wp.Action == Enum.PathWaypointAction.Jump then
if h:GetState() ~= Enum.HumanoidStateType.Jumping then
h:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
h:MoveTo(wp.Position)
end
end
hrp stands for humanoidrootpart and tHRP and tPos are the variables for the target with tHRP being the target’s humanoidrootpart and the tpos being the position of said humanoidrootpart. My goal is to make the ai spin around this position, while also moving with it, but I have no idea how to do it since I don’t know much on math
Arbitrary points on circle are rcos(thetha) and rsin(theta). Have your humanoid model at center and with changing values of theta you will have a locus of circle.
im sorry but IDK anything about implementing stuff like cos or sin into scripts like this, do you have any examples or anything that could help or anything to show how to implement this into my script? I tried to do your suggestion myself btw, but idk how to implement.
Well on second thought using cFrames might not be the best approach visual and would surely stress on server considering it has to go through every theta value and the movement will be jagged. Go with animation as Animations get replicated to server automatically when played in a local script.
I cant really want to do animations as I need it to be able to adjust to terrain around it without clipping through the floor or something if a mountain is nearby. Ill see what I can do with the cos, sin and radius of a circle stuff though
Yeah like @BumbleBee0_0 method, something like this post below:
However instead of setting the parts position to the circle you will need your AI to chase after the parts position in the circle generated by the code using :MoveTo() and path finding probably.