How do I make character face perpendicular from surface of a part

i need this for like wall hit detection or whatever. been trying to do this for the past few days. would prefer doing this with like cframe or vector math.

Look up CFrame.Angles() and you should get a result. Or use CFrame:LookTo()or CFrame:PivotTo()

let me make myself clear, the side of which the character should face perpendicular to isn’t yet decided, so i would need some way of getting the closest side to the character root. I illustrated what I am trying to achieve:

square being the part,
orange being the character root,
red being the orientation perpendicular to the closest “surface” or “face” to the character
green being orientation CFrame.new(wall.Position, character.HumanoidRootPart.Position)
…which is not what i am trying to achieve

image

– individual surfaces of part–

finally did it. i created virtual points in the center of each side, which would be something like part.Size.X/2 when i was supposed to be doing just part.Size.X. here’s the function;


local function getSide(object, root)
	
	local cf1, cf2 = object.CFrame, root.CFrame
	local size = object.Size
	local x, y, z, w = cf1+Vector3.new(size.X, 0, 0), cf1+Vector3.new(-size.X, 0, 0), cf1+Vector3.new(0, 0, size.Z), cf1+Vector3.new(0, 0, -size.Z)
	
	local l = {x,y,z,w}
	local n = {}
	local d = {}
	
	for i, v in pairs(l) do
		table.insert(n, l[i])
		table.insert(d, (v.p - cf2.p).Magnitude)
	end
	
	local min = n[table.find(d, math.min(table.unpack(d)))]
	local ori = CFrame.new(object.Position, min.p)
	local cframe = ori - ori.p

	return cframe
	
end

to apply it just add positional values to the cframe as they were removed

1 Like