How can I get the direction wedge facing (vector direction)


Wedges, as triangles, do not have a vector that can easily tell where they are facing.

They just have the classic vectors, such as LookVector, RightVector, and UpVector.
I think I could use RightVector and LookVector along with the sizes to calculate the direction the wedge’s face is pointing, but I have no idea how.

I want a direction just like LookVector provides.

I think I did it


How I calculated the direction

function module.GetWedgeFaceDirection(Wedge:BasePart)
local z = Wedge.Size.Z
local y = Wedge.Size.Y
	
local NewVector = (Wedge.CFrame.LookVector*z) - (Wedge.CFrame.UpVector*y)

return NewVector
end

Making a part face the direction

local Direction = module.GetWedgeFaceDirection(script.Parent)

local PartOrientation = CFrame.lookAt(script.Parent.Position, script.Parent.Position+Direction)


other stuff

-- Flips a wedge while keeping the same looks.
function module.WedgeFlip(Wedge:BasePart)
	local Targets:BasePart = {Wedge}

	for _, Target in Targets do
		local Orientation = Target.Orientation 
		Target.Orientation = Vector3.new(Orientation.X, Orientation.Y-90, Orientation.Z-180)

		local X = Target.Size.X
		local Y = Target.Size.Y
		local Z = Target.Size.Z

		Target.Size = Vector3.new(X, Z, Y)
	end
	
end

-- Returns the length of a wedge's slope.
function module.GetWedgeSlopMagnitude(Wedge:BasePart)
	local Origin = Wedge.Position
	
	local Y = Wedge.Size.Y/2 -- UpVector
	local X = Wedge.Size.X
	local Z = Wedge.Size.Z/2 -- LookVector
	
	local CornerA = (Wedge.CFrame.LookVector*Z) - (Wedge.CFrame.UpVector*Y)
	local CornerB = -(Wedge.CFrame.LookVector*Z) + (Wedge.CFrame.UpVector*(Y))
	
	return (CornerA-CornerB).Magnitude
end
2 Likes

Hi there, so what I did was take 2 points and then some math and then bam. (I’m, not 100% sure what I’m doing as I’m very tired, but it works).

Script
local part = workspace:WaitForChild("Part")
local pointA = Vector3.new(-part.Size.Z / 2, -part.Size.Y / 2, 0)
local pointB = Vector3.new(part.Size.Z / 2, part.Size.Y / 2, 0)

local lookAlong = CFrame.lookAlong(pointA, pointB - pointA, Vector3.new(0, 1, 0)) * part.CFrame
local direction = lookAlong.UpVector
Attempt to explain

image
So how it works is that it takes the direction from point A to B
and then takes the upvector of that which is what you need.

1 Like

o wow that method I could’ve done too I’m surprised I didn’t think of that

1 Like

Oh cool, how did you do it then?

I just updated my solution with code, turns out I was over complicating it the whole time it was easier than I thought

1 Like

Oh damn, you have done it 100 times easier than me haha, goodluck with your project mate.

1 Like

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