Raycast Orientation

So I’ve been having trouble with making this part face the way that the player is looking whilst also spawning ontop of the raycast’s normal. I have the the raycast shooting down to detect that part the player is standing on. The part spawns perfectly on the normal, it just the orientation that I’m having a problem with. How do I go about doing this

This is my problem:


I want this brown part to face the way the player is facing


This is the part on a wedge

local currentPivot = Character:GetPivot()
		print(currentPivot)
		
		local set_front_vector = Vector3.new(0, 1, 0) -- // This will make it so it will always look up in a way
		local right_vector = set_front_vector:Cross(cast.Normal)
		local cframe = CFrame.fromMatrix(cast.Position + Vector3.new(0,0,0), right_vector, cast.Normal)
	
		EarthWall:PivotTo(cframe)

This method seems to be working quite well for me:

local lookVector = Character:GetPivot().LookVector

local cframe = CFrame.lookAlong(cast.Position + cast.Normal, lookVector, Vector3.yAxis)

EarthWall:PivotTo(cframe)

You might need to adjust the cast’s normal depending on the size of your wall, as an example if the wall is 4 studs cubed you’ll need to do this:

local lookVector = Character:GetPivot().LookVector

local cframe = CFrame.lookAlong(cast.Position + cast.Normal * 2, lookVector, Vector3.yAxis)

EarthWall:PivotTo(cframe)
1 Like

oh my god bless your soul, i was ripping my hair out

1 Like