|
| 16 Jun 2013 05:37 PM |
This is the current script im using for a roll away thing,it glicthes and sometimes Does the comeplete oppisite of what its supposed to do, basicly,its supposed to use body force to roll away from anyone near it,But this script is glicthy and only rolls away in 1 set direction even if you are in the way of that direction,or sometimes it goes slower than its supposed to and rolls tword the target, Script is this: local egg = script.Parent function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 40 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.Position) if target ~= nil then script.Parent.BodyForce.force = (-target.Position) wait(.50) script.Parent.BodyForce.force = Vector3.new (0,0,0) end end
help? please? |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2013 05:48 PM |
I don't know BodyForce that well, but maybe you are not supposed to set the force to the negative position but the positive. And I have no clue why you would wait .5 seconds then make it 0 again, that would make it move to the middle of the game as soon as it starts going to -target.Position.
Hope this helps!
-- cardgamechampion/AlternativeAcc |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2013 06:49 PM |
| It can be negative,and i also nee to to roll away when something else gets in its way (another human) so,i put it to .5 |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
| 17 Jun 2013 02:52 PM |
u want a relative position & a direction (This WILL contain errors!):
local Power = 100 -- ? Make-up some number
while true do wait(0.1) local target = findNearestTorso(script.Parent.Position) if target ~= nil then
local dist = script.Parent.Position - target.Position local dir = dist.unit -- (Check the Wiki for the exact syntax on this) local v = dir * Power -- a Velocity
script.Parent.BodyForce.force = (v) -- or v*-1 (My math is a little fuzzy) (Plus, sorry, I have never used BodyForce)
wait(.50) script.Parent.BodyForce.force = Vector3.new (0,0,0) end end
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2013 03:06 PM |
Another way:
local Power = 100 -- ? Make-up some number
while true do wait(0.1) local target = findNearestTorso(script.Parent.Position) if target ~= nil then
local dir = target.CFrame.lookVector * -1-- Roll in the opposite direction that the Player is looking local v = dir * Power -- a Velocity
script.Parent.BodyForce.force = (v) -- or v*-1 (My math is a little fuzzy) (Plus, sorry, I have never used BodyForce)
wait(.50) script.Parent.BodyForce.force = Vector3.new (0,0,0) end end |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2013 03:08 PM |
*local dir = target.CFrame.lookVector -- Roll in the direction that the Player is looking
I guess we should roll in the direction he IS looking..... It should sneak-up on him, than run away, when he looks back. |
|
|
| Report Abuse |
|
|
|
| 17 Jun 2013 03:58 PM |
" attempt to call global 'findNearestTorso' (a nil value)" D:? |
|
|
| Report Abuse |
|
|