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: Raycasting won't work!

Previous Thread :: Next Thread 
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:01 PM
while wait(.1) do

local ray = Ray.new(script.Parent.Torso.CFrame.p,getPlayer(script.Parent.Torso.Position).CFrame.lookVector)

local part = workspace:findPartOnRay(ray)

--getPlayer(position) returns a Torso.

if part then

print("Wall")
else

print("!Wall!")

end

end

I'm almost positive I'm coding it correctly, but it only prints "!Wall!" when there is, in fact, a part intersecting. If I'm not coding it correctly, then please tell me.
Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
23 Aug 2012 08:03 PM
Making an AI, are you?
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:04 PM
No. ;3
Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
23 Aug 2012 08:05 PM
Yeah, sure... :3.
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:05 PM
So uh, help ? Hahaa
Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
23 Aug 2012 08:07 PM
I'm only good with ray casting guns.. XD.
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
23 Aug 2012 08:07 PM
@Cease,
Outside of it he could have a mousebutton1Down/Up function.
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:09 PM
Well I used:

Spawn(function())
--loop
end)

I don't want to post the rest of my script, it works fine.
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
23 Aug 2012 08:11 PM
Okay,
Guess it is AI,
GOOOD LUCK!
Report Abuse
BobbyisLOLZ is not online. BobbyisLOLZ
Joined: 17 Aug 2010
Total Posts: 8045
23 Aug 2012 08:13 PM
Reported mamaguy.
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:14 PM
What? Why? Anyway, I need help please. :3
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
23 Aug 2012 08:14 PM
@Bobby,
For what, just because I stated a fact that you're a low life piece of scum?
Report Abuse
BobbyisLOLZ is not online. BobbyisLOLZ
Joined: 17 Aug 2010
Total Posts: 8045
23 Aug 2012 08:15 PM
What did I ever do to you lol
I just said reported.
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
23 Aug 2012 08:16 PM
You scammed my friend, and flamed me.
Report Abuse
BobbyisLOLZ is not online. BobbyisLOLZ
Joined: 17 Aug 2010
Total Posts: 8045
23 Aug 2012 08:17 PM
What items did I take, and I never flamed you. ALL you ever do is just look where I post, and then flame me. You got your clockwork headphones, now stop Q_Qing, k? Thanks.
Report Abuse
StygianBlade is not online. StygianBlade
Joined: 15 Sep 2011
Total Posts: 426
23 Aug 2012 08:20 PM
"getPlayer(script.Parent.Torso.Position).CFrame.lookVector)"

Mind explaining the getPlayer function?
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:26 PM
getPlayer(pos) finds the nearest Torso.

getPlayer(pos).CFrame.lookVector is the lookVector of the Torso.
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 08:33 PM
Well, the direction it is facing.
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 10:21 PM
Bump bump bump, bump-it-up!
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
23 Aug 2012 11:38 PM
Boomp.
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
24 Aug 2012 12:09 AM
Filter frustration part 1/3:
Raycasts only work as far as the magnitude of the second argument, so the function is only looking for parts 1/2 a brick away from your torso XD
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
24 Aug 2012 12:10 AM
Do this:

    local pos=script.Parent.Torso.CFrame.p
    local tor=getPlayer(pos)
    local ray=Ray.new(pos,tor.CFrame.lookVector*((tor.Position-pos).magnitude+tor.Size.magnitude/2))
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
24 Aug 2012 12:11 AM
That way, the ray will go to at least the distance between them, + the part's size in case it's at an odd angle.
(end of filter frustration, I don't know what the problem was)
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
24 Aug 2012 12:24 AM
try that first, and if it doesn't work, try putting a - before the second argument, as lookVector actually returns a negated unitVector (lolwhy?)
Report Abuse
superior is not online. superior
Joined: 13 Apr 2008
Total Posts: 1662
24 Aug 2012 10:17 AM
How would I make it so that the ray always goes to the player? Right now, the ray goes in the direction the players torso is, so if the player turns around, the ray checks opposite of the start position. ?
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