How do I RayCast Straight Upwards

Hi, I’d like to shoot a Ray from a part I’ve created under the map, in the upwards direction. I want to use this to move the part to the result of the ray, as well as copy it’s color and material!

In this script, I actually shoot a ray straight downwards already, and that seems to be working just fine.

I tried reversing it, and now for some reason the ray’s from the parts are shooting straight downwards

(I tested this by creating a part below the parts and checking for a result)

Here’s my code:

for i = 0, craterPieces do
		local zRand = math.rad(math.random(-15,15))
		local part ="Part")
		part.CFrame = belowFloor*CFrame.Angles(0,math.rad(i*360/craterPieces),0) *,0,-4*2) * CFrame.Angles(math.rad(35),0,zRand)
		part.CanCollide = false
		part.Anchored = true
		part.Parent = workspace.fx
		local partPos = part.CFrame.Position
		local endPos = part.Position*,20,0)
		local newResult = workspace:Raycast(partPos, endPos, params)
		if newResult then
			part.Material = result.Material
			part.Color = result.Instance.Color
			warn("no result")

I’ve tried looking on the hub, I’ve watched YouTube videos, I’ve asked in servers, I’m stumped, thanks for the help!

P.S. this is to make a crater, lol

1 Like

Have the Direction face the Y Axis only:

Vector3.yAxis * Range
-- (0, 1, 0) times x (how far you want the ray to go)

what is:

Vector3.yAxis   -- (1, 1, 1)  -- (0, 0, 0)

Vector3.xAxis -- (1, 0, 0)
Vector3.yAxis -- (0, 1, 0)
Vector3.zAxis -- (0, 0, 1)   -- (1, 1)  -- (0, 0)

Vector2.xAxis -- (1, 0)
Vector2.yAxis -- (0, 1)

I tried that, now when I use it on the spawn location, one of the pieces get’s a result, the rest don’t.

Here’s a visual of what’s going on.


Tried is again, this happened,

So, I’m dumb, turns out I was spawning it inside of the baseplate, the solution worked, thanks!

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