lookathis
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 853 |
|
|
| 23 Feb 2013 05:05 PM |
Hey there I decided to start learning to script, so I decided to look into different scripts and try and change the values of them etc, and if possible, try and use it in my game.
The problem is that im trying to make a model follow me (And only me) and I have a script for that, however, the model follows me way to close to the torso and instead I wanted it to follow me 2-3 studs behind me. I was thinking of trying to place a "- 2" somewhere in the hope it would be "(temp.Position - pos - 2).magnitude < dist" however, I tried it in multiple places with no luck, so I was wondering if the forums could help me..
--- local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 20 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) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end ---
When I do at a "-2" the script usually gives up and doesnt follow me at all.
Thanks! |
|
|
| Report Abuse |
|
|
lookathis
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 853 |
|
|
| 24 Feb 2013 04:26 AM |
| Bump since no ones answered... |
|
|
| Report Abuse |
|
|
blockold
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1411 |
|
| |
|
lookathis
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 853 |
|
|
| 24 Feb 2013 04:55 AM |
| If you had no idea, then why did you answer the thread? It doesn't really help me in any way. |
|
|
| Report Abuse |
|
|
blockold
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 1411 |
|
|
| 24 Feb 2013 04:57 AM |
| Because I didn't want to make you feel worthless, with nobody actually answering this thread. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 24 Feb 2013 05:01 AM |
Never really worked with magnitude just yet, but you can make the script check if the distance between you two is only 3 studs. Maybe like this:
if plyr.magnitude - whateer
Idk lal |
|
|
| Report Abuse |
|
|
lookathis
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 853 |
|
|
| 24 Feb 2013 01:54 PM |
| Does anyone esle have any ideas on how to fix this? |
|
|
| Report Abuse |
|
|