Changing cframe to vector3 for raycasting

i am applying blood decals to limbs based on the side that lands on the floor however i am having issues with making sure that the raycast always points downwards.

local raycast = workspace:Raycast(bodypart.Position, (bodypart.CFrame.Position + CFrame.new(0, 1, 0) - bodypart.CFrame.Position), RaycastParams.new())
1 Like

You can convert a CFrame value into a Vector3 value by simply wrapping the CFrame value with a Vector3.new() like this:

local CFrameValue = CFrame.new(0, 0, 0)

local Result = Vector3.new(CFrameValue)
1 Like

this is returning nil, is this correct?

local raycast = workspace:Raycast(Vector3.new(bodypart.CFrame), Vector3.new(bodypart.CFrame) - (Vector3.new(bodypart.CFrame) + Vector3.new(0,1,0)), RaycastParams.new())

What is returning nil? The result of the raycast?

yes, the raycast is currently returning nil

You need to check for the raycast, aka the result. If the result is firing at the sky for example, it will return nil as the ray doesn’t hit anything and it can’t go forever.

Just add this simple if statement:

if Raycast then

end
2 Likes

this is still returning nil, i forgot to multiply the direction but it still doesnt work

local raycast = workspace:Raycast(Vector3.new(bodypart.CFrame), (Vector3.new(bodypart.CFrame) - Vector3.new(bodypart.CFrame) + Vector3.new(0,-5,0)) * 3, RaycastParams.new())

if you want to do a raycast facing downwards you should just do
workspace:Raycast(bodypart.CFrame.Position,Vector3.new(0,-1,0))

yeah but during ragdoll the body parts will tumble and i can’t be sure it will be facing down

@LeqenDzTR is right, Raycasting is in worlspace, which means that Vector3.new(0,-1,0) will always be 1 stud downwards, regardless of the character’s orientation.

1 Like

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