|
| 23 Apr 2014 10:57 AM |
I'm trying to raycast directly in front of my character for 100 studs (in the direction of the head's front surface):
ray=Ray.new(script.Parent.Head.Position,Vector3.new(script.Parent.Head.CFrame*CFrame.new(0,0,-100)).unit*100) local hit,position = game.Workspace:FindPartOnRay(ray,script.Parent)
However, it doesn't detect any hits even when an object is directly in front of the player (which leads me to assume I'm making a mistake with my raycasting). Can anyone tell me what the problem is and why? |
|
|
| Report Abuse |
|
|
| 23 Apr 2014 12:04 PM |
While in development, you should always draw the ray when u make one, and color it differently it it "hit" or not:
Also It looks like you are callin Ray, with two points; it wants a Point & a Direction (LookVector)...
((Sorry in this example from, Speed AI; the Direction is mis-named "Point"))
local GraphicsOn = true
function DrawRay(origin, point) -- 7 studs long (Makes & Draws a Ray) local Ray = Ray.new(origin, (point).unit * 7) --Make the ray. local Hit,Position = game.Workspace:FindPartOnRay(Ray,AI) --Check for collisions along the ray, ignoring any Parts of us.
if GraphicsOn then --Graphics local RayPart = Instance.new("Part",AI) if Hit then if Logic == 1 then RayPart.BrickColor = BrickColor.new("Black") --Set its color. else RayPart.BrickColor = BrickColor.new("Bright red") --Set its color. end else if Logic == 1 then RayPart.BrickColor = BrickColor.new("White") --Set its color. else RayPart.BrickColor = BrickColor.new("Olive") --Set its color. end end RayPart.Transparency = 0.2 --Set its transparency. RayPart.Anchored = true --Set whether it will fall or not. RayPart.CanCollide = false --Set whether people can walk though it or not. RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small. local Distance = (Position-origin).magnitude --Find the distance between the hit and the torso. RayPart.Size = Vector3.new(0.4,.2,Distance) --Set its size to the distance. RayPart.CFrame = CFrame.new(Position, origin) * CFrame.new(0,0,-Distance/2) --Move it halfway. game.Debris:AddItem(RayPart,2) --Add it to the debris. end -- Graphics
return Hit end -- DrawRay
This MAY work for u; may not:
ray=Ray.new(script.Parent.Head.Position, script.Parent.Head.CFrame.LookVector).unit*100)
local hit,position = game.Workspace:FindPartOnRay(ray,script.Parent)
*you NEED the .unit, even though LookVector is already a .unit, just to force Ray into shooting a 'finite' ray....
|
|
|
| Report Abuse |
|
|
| 23 Apr 2014 12:17 PM |
*Sorry, missing a bracket (That's why I don't code on -the-fly...)
ray=Ray.new(script.Parent.Head.Position, (script.Parent.Head.CFrame.LookVector).unit*100) |
|
|
| Report Abuse |
|
| |