Blockcast Normal direction

  1. What do you want to achieve?

I’m trying to make a part face the normal of the blockcast and later lerp the rig to face the direction of the normal

  1. What is the issue?

The only way I can make the part face the normal is if I set the orientation manually. I’ve tried to use Cframe.lookat() but it seems to be giving the slope of the object and not the direction of the surface.

the code

local humanoidrig = script.Parent
local humanoidrootpart = humanoidrig.HumanoidRootPart
local size = Vector3.new(1,1,1)

local directionpart = workspace.Direction
local visualizepart = Instance.new("Part")
visualizepart.Anchored = true
visualizepart.CanCollide = false
visualizepart.Size = size
visualizepart.Name = "VisualPart"
visualizepart.Transparency = .5
visualizepart.Parent = workspace

while true do
	task.wait()
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {humanoidrig, visualizepart, directionpart}
	params.FilterType = Enum.RaycastFilterType.Exclude
	local direction = humanoidrootpart.CFrame.UpVector*-5
	local blockcast = workspace:Blockcast(humanoidrootpart.CFrame, size, direction, params)
	if blockcast then
		print(blockcast.Instance)
		visualizepart.Rotation = humanoidrootpart.Rotation
		visualizepart.CFrame = humanoidrootpart.CFrame + direction.Unit * blockcast.Distance
		
		directionpart.Position = humanoidrootpart.Position + direction.Unit * blockcast.Distance
		directionpart.Orientation = humanoidrootpart.Orientation -- manually set the rotation

		-- slope angle directionpart.CFrame = CFrame.lookAt(directionpart.Position, directionpart.Position + blockcast.Normal)
	else
		print("no blockcast")
		
		visualizepart.Orientation = humanoidrootpart.Orientation
		visualizepart.Position = humanoidrootpart.Position + direction
		
		directionpart.Position = Vector3.new(0,0,0)
	end
end

here is manually setting rotation
https://gyazo.com/90d23af9a409329f9fcaf87db0687f81

here is using the slope angle comment code instead
https://gyazo.com/4f27fc0e9b62df898839f50578048afd

the angle with cframe.lookat looks like it works

if you mean the part is aligning with the wrong thing you could rotate it by something constant like CFrame.Angles(math.pi,0,0)

edit: also try rotating in z axis or both to get it right

I’m trying to make the part face the surface normal or away and perpendicular from the surface direction, right now it’s parallel. If you look in the gyazo, where I manually set the rotation is what I want, right now using the cframe.lookat it’s parallel.

What I’m trying to do
https://gyazo.com/c962d156e9e8196e369ade7216b310ad

Right now the part is parallel
https://gyazo.com/8f7a9fee65c782cebd859986bebdc4f3
https://gyazo.com/b028d88a379deea044ba38704e785649