generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Any other way?

Previous Thread :: Next Thread 
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
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
AlternativeAcc is not online. AlternativeAcc
Joined: 29 Mar 2012
Total Posts: 1337
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
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
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
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
16 Jun 2013 07:09 PM
Bump
Report Abuse
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
16 Jun 2013 07:52 PM
Bump1
Report Abuse
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
16 Jun 2013 08:15 PM
Bump2
Report Abuse
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
17 Jun 2013 06:20 AM
Bump3
Report Abuse
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
17 Jun 2013 02:37 PM
Bump # 1337...
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
icegroudon is not online. icegroudon
Joined: 08 Oct 2011
Total Posts: 2924
17 Jun 2013 03:58 PM
" attempt to call global 'findNearestTorso' (a nil value)"
D:?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image