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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

problem with raycast

Previous Thread :: Next Thread 
BlockzieCartI is not online. BlockzieCartI
Joined: 28 Sep 2009
Total Posts: 812
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
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
BlockzieCartI is not online. BlockzieCartI
Joined: 28 Sep 2009
Total Posts: 812
23 Apr 2014 02:54 PM
thanks bro, it worked
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