Rotating Hovercraft Issues

I hope yall recognized my car:
image

I love rotating said car
But when it is on incline, my method of rotating just decides to no longer work :C
image

Here is the deal, I am unaware of any math that is in my knowledge that can rotate a car along all 3 axises.
Currently I use the Euclidean method of rotating vectors (using 2d only).

local px = (x * math.cos(angle)) - (z * math.sin(angle))
local pz = (z * math.cos(angle)) + (x * math.sin(angle))

However as you can see, I am doing a rotation on the Y axis. What I need is a rotation along all axis to keep a perpendicular form.

Code
local function changeSteer(scal)
	if scal == 1 then
		if turn + tSpeed.Value < math.rad(360) then --because radians, ugh...
			turn = turn + tSpeed.Value
		else
			turn = math.rad(360) - (turn + tSpeed.Value)
		end
	elseif scal == -1 then
		if turn - tSpeed.Value > 0 then
			turn = turn - tSpeed.Value
		else
			turn = (turn - tSpeed.Value) + math.rad(360)
		end
	end
	--print(turn)
	
	local stabFold = car.StabilityPoints
	
	for _, poin in pairs(stabFold:GetChildren()) do
		local _,_, fN = castRay(poin, Vector3.new(0, -1, 0), 500000)
		normAve = ((normAve.Unit + fN.Unit)/2).Unit
	end
	
	local uAve = Vector3.new(0, normAve.Z, -normAve.Y) --perpendicular time
	local angle = math.acos(uAve:Dot(physRoot.CFrame.LookVector))
--	if math.abs(angle) > 90 then
--		uAve = -uAve
--	end
	
	--rotate it with the angle of turn
	local px = (uAve.X * math.cos(turn)) - (uAve.Z * math.sin(turn))
	local pz = (uAve.Z * math.cos(turn)) + (uAve.X * math.sin(turn))
	uAve = Vector3.new(px, uAve.Y, pz)
	
	--change that, broth
	gyro.CFrame = CFrame.new(physRoot.Position, (physRoot.Position + uAve))
end

Can anyone lead me to a wikipedia page on what I need? Or potentially explain a fault in my code? Would I need quaternions?

1 Like

Would there be a way to rotate an object in local space? How exactly would I do so?

Solved in separate thread: