How to raycast outward with a lookvector? (Lidar)

I am wanting to know how to raycast from a point, which would be the camera position, onto a grid that is facing the player. I’m able to achieve part of this until I start looking towards the z axis.


I am pretty confident that the issue lies in defining the z value to make it face me. Here is the code that I use for it:

One source I did find that was helpful was this, as stated before this also comes close to what I want but just make it rotate to the lookvector of the player. Thanks you.

-- Your existing variables and setup code

-- Loop for raycasting
for _, Lidar_Box_Range_Lidar_Box_Range do
    -- Calculate the direction of the raycast
    local direction = (Lidar_Range * CFrame.lookVector * Vector3.new(1, 1, 1)) -- Ensure the z value is included correctly
    -- Perform the raycast
    local ray_object = workspace:Raycast(Camera.CFrame.Position, direction, raycastParams)
    -- Check if the raycast hit an object
    if ray_object then
        -- Check if the hit object is a 'BasePart' and named 'Lidar_particle'
        if ray_object.Instance:IsA("BasePart") and ray_object.Instance.Name == "Lidar_particle" then
            -- Set the position of the 'hit' part to the raycast hit position
            script.Parent.handle.hit.WorldPosition = ray_object.Position
        end
    end
end

Thank you for the response but I ended up answering my own question. If anyone else wants to know the solution here it is:


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