-
What do you want to achieve?
I want to make a rig chase the player for my game. -
What is the issue?
So I tried making one but the algorithm usually get confuse. Also I’m trying to make it very reactive and smooth (no delay when I change place) like the others roblox games but fail. -
What solutions have you tried so far?
I tried looking on youtube for scripts and explanation but I couldn’t fix the problem. The scripts of people on youtube looks very similar to mine but works unlike mine.
Video :
Here the script I use :
local Rig = workspace.Hunter
local PathFinding = game:GetService("PathfindingService")
local RunService = game:GetService("RunService")
local Players = game.Players:GetPlayers()
local Range = 80
local Start = Rig.HumanoidRootPart.Position
local End = workspace.End.Position
local LastTarget
local function Trace(waypoint)
local Part = Instance.new("Part", workspace)
Part.Position = waypoint.Position + Vector3.new(0,1,0)
Part.Size = Vector3.new(3,3,3)
Part.Anchored = true
Part.CanCollide = false
Part.Color = Color3.new(0.447059, 1, 0.0235294)
end
--Rig.Humanoid.JumpPower = 100
local function Recalculate (Target)
-- print("calculating.. for target : ",Target.Name)
local Path = PathFinding:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = true,
--Costs = {
-- --Plastic = math.huge,
-- --Ice = 0
--}
}
)
Path:ComputeAsync(Rig.HumanoidRootPart.Position, Target.HumanoidRootPart.Position)
-- print("calculated")
return Path
end
local NewAction = false
local TargetIdx = 0
local function Target(target)
--print("new")
local Path = Recalculate(target)
local HRP = target.HumanoidRootPart
local Waypoints = Path:GetWaypoints()
if Path.Status ~= Enum.PathStatus.Success then return end
for i, waypoint in pairs(Waypoints) do
print("moving to : ",i)
if waypoint.Action == Enum.PathWaypointAction.Jump then
Rig.Humanoid.Jump = true
end
Rig.Humanoid:MoveTo(waypoint.Position)
--Trace(waypoint)
Rig.Humanoid.MoveToFinished:Wait()
end
end
local LastPosition
RunService.Heartbeat:Connect(function()
local Players = game.Players:GetPlayers()
for i, plr in ipairs(Players) do
plr = workspace:FindFirstChild(plr.Name)
local HRP = plr:FindFirstChild("HumanoidRootPart")
if not HRP then return end
if (plr.HumanoidRootPart.Position - Rig.HumanoidRootPart.Position).Magnitude <= Range then
Target(plr)
NewAction = true
end
end
end)
How can i fix my script ? Does someone has a better way to complete my goal ?