RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
|
| 20 Jul 2014 01:36 PM |
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.x > -maxdist and dist.z < 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
|
|
|
| Report Abuse |
|
|
| |
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
|
| 20 Jul 2014 01:42 PM |
| It's a RPG enemy he, the name is Enemy of the humanoid. |
|
|
| Report Abuse |
|
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
| |
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
| |
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
| |
|
bibo5o
|
  |
| Joined: 17 Jan 2009 |
| Total Posts: 414 |
|
|
| 20 Jul 2014 05:58 PM |
| Sorry real, I don't think people are ignoring this, they probably just don't understand what's going on. |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2014 06:22 PM |
if dist.x < maxdist and dist.x > -maxdist and dist.z < 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. |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2014 06:24 PM |
| I think people just don't want to read bulk scripts. |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2014 06:29 PM |
script.Parent["Enemy"]:MoveTo(target.Position, target)
Try removing the ", target". |
|
|
| Report Abuse |
|
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
|
| 21 Jul 2014 04:05 AM |
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. |
|
|
| Report Abuse |
|
|
|
| 21 Jul 2014 11:27 AM |
| That probably means that the script runs right at the creation of the server. |
|
|
| Report Abuse |
|
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
| |
|
CWRA0444
|
  |
| Joined: 14 Jan 2010 |
| Total Posts: 6013 |
|
|
| 21 Jul 2014 02:02 PM |
| add a wait(2) before everything |
|
|
| Report Abuse |
|
|
RealistK
|
  |
| Joined: 20 Feb 2011 |
| Total Posts: 3489 |
|
| |
|
|
| 21 Jul 2014 05:09 PM |
| lol i remember when i was creating rpg i had same error brb |
|
|
| Report Abuse |
|
|