Platform Orientation

Hi guys,

So I want to make a platform that gets its orientation from 4 points.
I’ve been searching all over google and all i get is calculations that only use 3 points.

My question is: Do you happen to know the right calculation for this?

Why would you need to use four points?

its for a vehicle. a car to be specific wich has 4 tires. if i dont use all 4. the car will look weird if the one point thats not used is on another hight then the rest.

all 4 tires have to effect the cars orientation.

You could try generating 2 CFrames with orientation 3 points swapping out the point.

Then you could average the orientations using CF1:Lerp(CF2, 0.5).

You could also average the points.

What kind of car is it? That also determines whether it looks good or not.

thnx i will try that.

Just any car. I want to make a car game.
But i am NOT using roblox’s own physics lol.
I know better…

I’ve made a car using four thrusters that push the car up, and that kinda gets the orientation.

I’d recommend making a raycast downwards for all four wheels and then averaging the normals out to get your orientation.

could you give me a code example? I’m not great at maths

tried this:

function getRootCFrame(frontLeft, frontRight, backRight, backLeft)
	
	local center = (frontLeft + frontRight + backRight + backLeft) / 4
	
	local x = center.X
	local y =center.Y + 2
	local z = center.Z
	
	local front = (frontLeft - backLeft).unit
	local right = (backRight - backLeft).unit
	local up = right:Cross(front)
	
	local front_r = -(backRight - frontRight).unit
	local right_r = -(frontLeft - frontRight).unit
	local up_r = -right_r:Cross(front_r)
	
	
	local result = CFrame.new( x, y, z, right.x, up.x, -front.x, right.y, up.y, -front.y, right.z, up.z, -front.z )
	local result_revers = CFrame.new( x, y, z, right_r.x, up_r.x, -front_r.x, right_r.y, up_r.y, -front_r.y, right_r.z, up_r.z, -front_r.z )
	
	return result:Lerp(result_revers, .5)
end

doesnt seem to work so well…

I think you should be using CFrame.fromMatrix instead. It’s much easier to handle the math.

Well I tried that. And uhm I broke the engine. The platform litterly became flat. I went from 3D to 2D.

Could you give me an example of how to implement fromMatrix ?

fromMatrix uses the vectors, like xAxis, yAxis, and zAxis, to create a rotated CFrame.

It’s equivalent to CFrame.xVector, CFrame.yVector, and CFrame.zVector, but it’s a constructor. It also accepts positional arguments as the first three arguments.