#Can someone make me an entity like this?
1 messages · Page 1 of 1 (latest)
best I can do is this.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
--if player is lightbearer then aggro otherwise return end
local StalkerPath = game:GetService("PathfindingService"):CreatePath({
AgentCanJump = true
})
task.wait(1)
game:GetService("RunService").Heartbeat:Connect(function()
local success,errorMsg = pcall(function()
StalkerPath:ComputeAsync(script.Parent.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position)
end)
if success and StalkerPath.Status == Enum.PathStatus.Success then
for i,waypoint in pairs(StalkerPath:GetWaypoints()) do
local Distance = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
if Distance <= 40 then
local Direction = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Unit
script.Parent.Humanoid:MoveTo(script.Parent.HumanoidRootPart.Position - Direction * 7)
end
if Distance <= 50 then return end
if Distance <= 20 then
script.Parent.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position)
else
script.Parent.Humanoid:MoveTo(waypoint.Position)
end
script.Parent.Humanoid.MoveToFinished:Wait()
if waypoint.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
end
end
end)
end)
end)
For some reason the path finding is JUST fine when aggrod, but when fleeing it will bump into walls
Like the bracken from lethal company kinda creature?
just make it so when the player goes to close to monster the monster runs away, and to make it idle code a pathfinding or sum, i can try to make it
might take me a bit
if you can that would be crazy lol
I been trynna do this for 3 hours
still at square one
Just use magnitude checks and change the NPC's state to chasing/idle/fleeing based on distances
high-level pseudo:
FleeRange = 20
ChaseRange = 30
--(anything between is buffer)
--in your pathfinding loop (task.wait(0.1) for example)
while task.wait(0.1)
CurrentDist = (PlayerPos - EntityPos).Magnitude
if CurrentDist <= FleeRange then
--flee logic, avoid player
elseif CurrentDist >= ChaseRange then
--chase logic, pathfind to player
else
--idle
end
end
hmm I can try
ye ill try rq
ill make a beta with like
no animation n stuff
like this?
local fleeRange = 20
local AggroRange = 30
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
--if player is lightbearer then aggro otherwise return end
local StalkerPath = game:GetService("PathfindingService"):CreatePath({
AgentCanJump = true
})
task.wait(1)
while task.wait(0.1) do
local Distance = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
if Distance <= fleeRange then
print("Flee")
local Direction = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Unit
StalkerPath:ComputeAsync(script.Parent.HumanoidRootPart.Position,script.Parent.HumanoidRootPart.Position - Direction * 7)
for _,waypoint in pairs(StalkerPath:GetWaypoints()) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
end
elseif Distance >= AggroRange then
print("Aggro")
StalkerPath:ComputeAsync(script.Parent.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position)
for _,waypoint in pairs(StalkerPath:GetWaypoints()) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
end
else
print("Idle")
end
end
end)
end)
This don't work, no pathfinding.
Just bumps into walls, don't manuever
wtf
yeah so best I can get is this.
local fleeRange = 20
local AggroRange = 30
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
--if player is lightbearer then aggro otherwise return end
local StalkerPath = game:GetService("PathfindingService"):CreatePath({
AgentCanJump = true
})
task.wait(1)
while task.wait(0.1) do
local Distance = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
if Distance <= fleeRange then
print("Flee")
local Direction = (player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Unit
StalkerPath:ComputeAsync(script.Parent.HumanoidRootPart.Position,script.Parent.HumanoidRootPart.Position - Direction * 15)
for _,waypoint in pairs(StalkerPath:GetWaypoints()) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
elseif Distance >= AggroRange then
print("Aggro")
StalkerPath:ComputeAsync(script.Parent.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position)
for _,waypoint in pairs(StalkerPath:GetWaypoints()) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
else
print("Idle")
end
end
end)
end)
But now he will bob back and forth, won't idle
aight so
right now
it does it once
but im working on it
i used something from my game
bc i have a type of stalker
the screenrecording is bad but it works rn
so
if u want it to do it once
thats that
and ill give u the script
but i can make it do more
I want it to be constant
kk
like a stalker