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
 

Problem with Raycasts

Previous Thread :: Next Thread 
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
29 Jun 2013 05:26 AM
I'm currently having some trouble raycasting.

I'm raycasting from my character's head pointed at the Camera's CoordinateFrame, if you ask where I'm raycasting.

For some reason, my ray picks up my character's Hats perfectly fine and adjusts it (which I need to fix too, but current though it to just remove them completely) and it doesn't detect the parts I want it to - which is the terrain.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
29 Jun 2013 05:27 AM
Whoops, forgot to provide the script's source. Here's the part that matters:

game:GetService("RunService").Stepped:connect(
function()
cam.CameraSubject = char.Head
cam.CameraType = "Scriptable"
cam.CoordinateFrame = CFrame.new(char.Head.CFrame.p + Vector3.new(-5, 15, 30), char.Head.CFrame.p)
local hitRay = Ray.new(char.Head.CFrame.p, (cam.CoordinateFrame.p - char.Head.CFrame.p).unit)
local part, hit = workspace:FindPartOnRay(hitRay) --,char:GetChildren())
local dist=0
if part then
dist = (hit - char.Head.CFrame.p).magnitude
print(dist)
end
cam.CoordinateFrame = CFrame.new(char.Head.CFrame.p + Vector3.new((-5 + dist), (15 - dist), (30 + dist)), char.Head.CFrame.p)
if not active then
char.Torso.CFrame = CFrame.new(char.Torso.CFrame.p,Vector3.new(mouse.Hit.p.X, char.Torso.CFrame.p.Y, mouse.Hit.p.Z))
end
end
)

All variables have been defined, as that's just a snippet.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
29 Jun 2013 05:28 AM
also, should've made myself clearer.

By 'terrain' I didn't mean the Terrain object, I meant the building that I had done around the spawn I had put in.
Report Abuse
bourlo is not online. bourlo
Joined: 11 Aug 2009
Total Posts: 399
29 Jun 2013 05:43 AM
So does it always return your hats?
FindPartOnRay () returns only the first part it finds on a ray,if that part is one of your hats then you can't get the terrain you want unless you ignore the character.
local part, hit = workspace:FindPartOnRay(hitRay,char)
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
29 Jun 2013 05:59 AM
I got it to work :D

Apparently it was only checking a small area, so I fixed it so it didn't.

I also fixed the hats.

:D
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
29 Jun 2013 07:33 AM
I thought .Stepped was deprecated?
Report Abuse
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
29 Jun 2013 11:30 AM
@Infocus - So is :Remove(), but it works better than :Destroy() at times.
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