Problems with Raycast

Hello!
I need some help using raycast.

My Objective: get instances in the mouse ray

What is going wrong: The raycast result always returns nil

I already tried: I search for simillar problems in the forum, but I still can’t understand what is wrong.

Code:

local pos, dir = m.hit.Position + Vector3.new(0,50,0), Vector3.new(0,-50,0)
local Rayresult = workspace:Raycast(m.hit.Position + Vector3.new(pos, dir)
print(Rayresult)
1 Like

You arent applying rhe direction for thr raycast to go towards.

The Second Argument should do that.

What is the rest of your information?
We can’t tell what your m.hit.Position will be so if you define all the variables we might be able to help.

You can also print(m.hit) before the raycast line to see what result you are working with.

Oops, This is the position of the mouse hit using :GetMouse(), Mouse.Hit.Position

The direction should be Vector3.new(0,-50,0), so it goes from the hit position of the mouse + Vector3.new(0,50,0).
Or Im doing something wrong in the direction?

You’re only using up one of the parameters of “Raycast”, the first parameter is the position origin, so the mouse position, the 2nd is the direction vector of the ray, and the third is the “RaycastParams”.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.