I’m making a throwing knife and i don’t use RayCasting very much. I’m trying to make a ray that ignores the character, etc. Here’s the script:
local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
tool.Activated:Connect(function()
local throwpos = mouse.Hit.p
local RightHand = plr.Character.RightHand
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {RightHand.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayresult = workspace:Raycast(RightHand, throwpos, RaycastParams)
print(rayresult)
end)
I’ve taken some examples from google, and my script seems to match. But somehow i still get this error:
I’d really appreciate it if someone could help me out!
Jaklic
(Jaklic)
#2
RightHand.Position is missing. In your case it uses Instance and not Vector3 as origin.
Thanks, it solved the error, but i don’t get the raycastresult? How would i get that?
1 Like
Bliksem18
(cos2005)
#4
I think you made a typo: it should be
local rayresult = workspace:Raycast(RightHand, throwpos, raycastParams)
with lowercase r
1 Like
Oh no! That worked, thanks. But somehow i get nil as result??
koen_deb
(koen_deb)
#6
What’s the error now? Show us your output.
Bliksem18
(cos2005)
#7
That can mean that the ray didn’t hit anything
Ok, but i’m pointing at the baseplate?
Edit: Nevermind, the baseplate is locked. I think thats the problem.
koen_deb
(koen_deb)
#9
Try print(rayresult.Position) rayresult contains multiple values you can read off.
Bliksem18
(cos2005)
#10
That shouldn’t be a problem. I think I know what the problem is. You should try this:
local rayresult = workspace:Raycast(RightHand.Position, throwpos - RightHand.Position, raycastParams)
koen_deb
(koen_deb)
#11
Yeah good idea, you can also use the UnitRay of the mouse.
Try this:
local rayresult = workspace:Raycast(RightHand.Position, (RightHand.Position - throwpos).Unit * 300, raycastParams)
I think that would be the best yeah! Thanks for helping!
Can i pass the direction and origin trough a RemoteEvent by doing this:
rayresult.Direction, RightHand.Position
(RemoteEvent Parameters)
Edit: Nevermind, i can’t didnt define it.
koen_deb
(koen_deb)
#14
Yeah, you should be able to.(charz)