Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Ai in Rpg enemys / distance from spawn?

Asked by 9 years ago

basically , in my rpg I want it so that if my enemy goes a certain distance from the spawnpoint (I can just use a block) then it walks back to the spawnpoint, so I was wondering if there was a way to measure the stud distance and make it so that it returns to normal spawn.. any help guys ?

if dist >= 10 then
script.Parent.Human:MoveTo(pos) -- dist being the stud distance , and pos being the spawnpoint (e.g)
end

Idk something like that... thanks , any help appreciated

1 answer

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
9 years ago
local spawnPoint -- define spawnpoint
local studDistance = 10 -- maximum distance from spawn allowed

while true do
    local dist = (spawnPoint.Position - 
            script.Parent.Torso.Position).magnitude
    if dist >= studDistance then
        script.Parent.Human:MoveTo(
            spawnPoint.Position, spawnPoint)
        wait(1)
    end
end

If you have any questions ask.

0
Thanks , this does work, and is helpful , but i just wanted to know why on line 7 you added spawnPoint.Positon and spawnPoint itself, why not one? Bubbles5610 217 — 9y
0
I believe they removed it by now, however there used to be a second parameter that required you to pass in the object you are moving to or at least a description of it, Habit I guess. Lacryma 548 — 9y
Ad

Answer this question