#Can someone make me an entity like this?

1 messages · Page 1 of 1 (latest)

woven tiger
#

The NPC stalks the player: it flees when too close, idles in a buffer zone, and chases when the player is far. Before you tell me to use AI I have tried, didn't work. Didn't give me what I wanted and didn't work how its supposed to, I tried and failed. I doubt anybody can make this lol but if u can lmk!

#

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

primal iron
#

Like the bracken from lethal company kinda creature?

quartz comet
#

might take me a bit

woven tiger
#

I been trynna do this for 3 hours

#

still at square one

whole basin
# woven tiger The NPC stalks the player: it flees when too close, idles in a buffer zone, and ...

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
quartz comet
#

ill make a beta with like

woven tiger
#

thxs

quartz comet
#

no animation n stuff

woven tiger
#
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

quartz comet
#

right now

#

it does it once

#

but im working on it

#

i used something from my game

#

bc i have a type of stalker

woven tiger
#

kk

#

imma watch half of narnia

#

ill lyk when im back

quartz comet
#

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

woven tiger
quartz comet
woven tiger
#

like a stalker