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 |
|
|
|
| 06 Mar 2015 07:55 PM |
| It isn't From and To for the constructors, it is From and Direction. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 06 Mar 2015 07:58 PM |
Ray.new(Origin, Direction) v.Character.Torso.CFrame.p is not a direction. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 06 Mar 2015 07:59 PM |
| Wait, how do I set a direction? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 06 Mar 2015 08:12 PM |
| if hit and hit == TargetPart then |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 06 Mar 2015 09:49 PM |
| What about it isn't working? |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 06 Mar 2015 09:52 PM |
| So the script always goes into the case of *not* hit? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
|
| 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
|
  |
| 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
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|