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 » Scripters
Home Search
 

Re: Raycasting

Previous Thread :: Next Thread 
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 07:54 PM
I'm trying to cast a ray between a zombies body and a players torso. V is the characters model from a previous for loop. This script is inside the model of the zombie.

local ray = Ray.new(script.Parent.Torso.Position, v.Character.Torso.Position)
local hit, position = game.Workspace:FindPartOnRay(ray, script.Parent)

How do I make this work?


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Mar 2015 07:55 PM
It isn't From and To for the constructors, it is From and Direction.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 07:57 PM
This any better?
local ray = Ray.new(script.Parent.Torso.CFrame.p, v.Character.Torso.CFrame.p)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Mar 2015 07:58 PM
Ray.new(Origin, Direction)
v.Character.Torso.CFrame.p is not a direction.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 07:59 PM
Wait, how do I set a direction?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Mar 2015 08:00 PM
Subtract two positions and you have the direction. Wait no, that doesn't make sense. Okay, so "direction" might not be the right term, but what I said still goes. Subtract the two positions.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 08:03 PM
I got the ray to work. I want it so that if there is a wall in between the player and the zombie, the zombie won't pursue. Do I need to do something like

if hit then
or
if not hit then
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Mar 2015 08:12 PM
if hit and hit == TargetPart then
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 08:18 PM
What do I define TargetPart as? Because v.Character and v.Character.Torso doesn't work
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 08:47 PM
Yeah, I just want to check if the ray hits like a wall in between
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 09:14 PM
And you're offline

:(
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
06 Mar 2015 09:21 PM
I want it so that if there is a wall in between the player and the zombie, the zombie won't pursue.

Doesn't that answer your question
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
06 Mar 2015 09:23 PM
local ray = Ray.new(script.Parent.Torso.Position, (v.Character.Torso.Position - script.Parent.Torso.Position).unit)
local hit, position = game.Workspace:FindPartOnRay(ray, script.Parent)

Subtracting the positions and getting the unit vector will result in the direction you need.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 09:34 PM
I got the actual ray to work, but I need to know how my if statement should be. Right now it doesn't work


if hit then / if not hit then
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
06 Mar 2015 09:49 PM
What about it isn't working?
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 09:50 PM
The zombie will still engage me if there is a wall in between us. I'm trying to do it only if the zombie has visual on you.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
06 Mar 2015 09:52 PM
So the script always goes into the case of *not* hit?
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 09:53 PM
I guess it just goes straight through the wall in between me and the zombie. I've got zero experience with raycasting.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
06 Mar 2015 10:49 PM
I just need to know if something obstructs the path of the ray.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
06 Mar 2015 10:52 PM
I'm guessing you'll need to make sure that it's the wall it's hitting and not your player. The only thing is, if it always engages you then that would mean it's not finding anything, which is a little odd.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
07 Mar 2015 09:28 AM
Wait, does the ray go through the wall or does it end at the wall?
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
08 Mar 2015 07:08 PM
Any raycast experts?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
08 Mar 2015 07:29 PM
Theoretically, rays go on forever, but FindPartOnRay will find the first occurrence, so it won't detect anything beyond the wall unless you ignore the wall.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
10 Mar 2015 05:59 PM
Output: Unable to cast value to objects (Hit line)

local Ray = Ray.new(script.Parent.Torso.CFrame.p, (script.Parent.Torso.CFrame.p - v.Character.Torso.CFrame.p).unit*dist)
local Hit = game.Workspace:FindPartOnRayWithIgnoreList(Ray, script.Parent.Torso)
if Hit and Hit == v.Character then
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
10 Mar 2015 06:03 PM
I think I got it. Thanks
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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