How to make ray come out from the bottom of a part?

How do I make it so that the ray comes out of a bottom of a part?
Here’s my code (I’m fairly new to scripting rays)

local startP = script.Parent.Start.Position
local endP = script.Parent.End.Position

local rayOrigin = startP
local rayDirection = startP.CFrame * CFrame.Angles(math.rad(-90),0,0)

local ray = Ray.new(rayOrigin, rayDirection)

local Baseplate = workspace:FindPartOnRay(ray)
print(Baseplate) -- the ray should point towards the baseplate so the output should put out baseplate (right?)

Please let me know if there’s any way to go about this, thanks!

Theres a new method of raycasting, the one you’re using is deprecated. The code below should work.

local startP = script.Parent.Start.Position


local rayOrigin = startP
local rayDirection = (startP.Y - startP.Y) + -10

local ray = workspace:Raycast(rayOrigin, Vector3.new(0,rayDirection,0))

local Baseplate = ray
print(Baseplate) -- the ray should point towards the baseplate so the output should put out baseplate (right?)

I just tried it and it still prints nil, am I doing something wrong

You need to increase the - negative value. The direction only goes down 10 studs.

First of all, Ray.new() is bad, use Workspace:Raycast()

Now that you know that, I would do it like this:

local startP = script.Parent.Start

local ray = game:GetService("Workspace"):Raycast(startP.Position, startP.CFrame.UpVector * CFrame.new(0, -100, 0))

local baseplate = ray.Instance

print(baseplate.Name)

Your example does not work, it errors on line 3.

what is the error? I made that without testing and real quick

The 2nd parameter of Raycast takes a Vector3. You also tried to multiply a Vector3 to a CFrame.

Thanks! I think I understand how it works now.

No problem, glad to help you out.

1 Like