RealistKJoin Date: 2011-02-20 Post Count: 3489 |
So when you get near a monster and then you run out of their maxdistance, they are supposed to walk back, but what they do is:
You suddenly control them, if you press up they go down, if you press left they go right.
Weird..
how do I fix it that they just walk back to their original position?
Value with distance and a value with maxdistance in the script.
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
maxdist = script.MaxDistance.Value
start = script.Parent.Torso.Position
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = script.Distance.Value
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(0.1)
local target = findNearestTorso(script.Parent.Torso.Position)
newdist = script.Parent.Torso.Position
dist = newdist - start
print(dist)
if dist.x -maxdist and dist.z -maxdist then
if target ~= nil then
script.Parent["Enemy"]:MoveTo(target.Position, target)
end
else
script.Parent["Enemy"]:MoveTo(start)
end
end
|
|
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
It's a RPG enemy he, the name is Enemy of the humanoid. |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
meep |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
bump |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
bump |
|
bibo5oJoin Date: 2009-01-17 Post Count: 414 |
Sorry real, I don't think people are ignoring this, they probably just don't understand what's going on. |
|
|
if dist.x -maxdist and dist.z -maxdist then
if (dist.x*dist.x + dist.z*dist.z) < maxdist*maxdist then --a^2 + b^2 == c^2, like magnitude but fasterer. |
|
|
I think people just don't want to read bulk scripts. |
|
|
script.Parent["Enemy"]:MoveTo(target.Position, target)
Try removing the ", target". |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
Removing target didn't work. :s
The weirdest part is that it works fine in play solo, but it doesn't work in the actual server. |
|
|
That probably means that the script runs right at the creation of the server. |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
hmm, how to fix? |
|
CWRA0444Join Date: 2010-01-14 Post Count: 6013 |
add a wait(2) before everything |
|
RealistKJoin Date: 2011-02-20 Post Count: 3489 |
everything..? |
|
|
lol i remember when i was creating rpg i had same error brb |
|