Keeping a hovercar upright based on angle of surface?

Hi. I currently have a hover car, and I have completed the lift mechanics of it. I was wondering how I should go about keeping it upright since right now, one slight imbalance causes it to go crazy:

https://gyazo.com/95e141094efecd439ac51c572d6feafa

Thanks.

2 Likes

What are you using/doing right now to keep it floating?

I’m currently using 4 vector forces. One for each thrust point.

I guess the most naive approach would be to cast four rays downward (each Heartbeat), one at each attachment, and increase/decrease the force based on the distance (smaller distance = larger force). You can probably either trial and error the absolute value for the forces or use the cart’s mass to calculate it, however that could prove difficult when you start to put payloads like characters on top of it.

3 Likes

Another possible solution would be to use the AlignOrientation constraint, CFrames, an Anchor block so you dont have to adjust each of the 4 forces and have it operate similarly to a helicopter.

https://gyazo.com/90a4baa0d4cde402efa52587af7ca611

2 Likes

Here is an example of the code, though it uses the deprecated workspace:FindPartOnRayWithIgnoreList and the dreaded wait(). This code only changes the orientation block (motor block on my head in the gif) while the AlignOrientation does the rest by applying the force which can be easily adjusted later on.

--Get Roblox Service
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character

--Constant Variables

--Define unit vector
local Xunit = Vector3.new(1, 0, 0)
local Yunit = Vector3.new(0, 1, 0)
local Zunit = Vector3.new(0, 0, 1)

--ray ignore list
mech = workspace:WaitForChild("Mech")
rayIgnore = {workspace.Mech,character}
--Initial Variable
local mechRight = workspace.Mech.Torso.CFrame.RightVector

--Variables for the ray on the sphere leg
local down = -Yunit*500
function roundVector(vector, unit)
  return vector - Vector3.new(vector.X%unit, vector.Y%unit, vector.Z%unit)
end

while true do
local startPoint = workspace.OrientationBlocks.MechOrientationBlock.Center.WorldPosition
local rightStartPoint =workspace.OrientationBlocks.MechOrientationBlock.RightSide.WorldPosition
--Orientation  block of the mech
local orientBlock = workspace.OrientationBlocks.MechOrientationBlock

--Where the detecting begins
normalRay = Ray.new(startPoint,down)
rightSide = Ray.new(rightStartPoint,down)

--fire the ray and get normal
local _,hitPos,hitNormal,_ = workspace:FindPartOnRayWithIgnoreList(normalRay,rayIgnore)
local _,hitPosDos,__,_ = workspace:FindPartOnRayWithIgnoreList(rightSide,rayIgnore)
	newRightSide = hitPosDos-hitPos
print(roundVector(hitPos,1)," / ",roundVector(hitPosDos,1)," / ",roundVector(newRightSide,1))
	normalDirection = hitNormal
	
	local rotatedCFrame = CFrame.Angles(0, 0, 0)
	--begin creating the right vector to control the mechs direction on the zx plane
	local aHeld = UserInputService:IsKeyDown(Enum.KeyCode.A)
	local dHeld = UserInputService:IsKeyDown(Enum.KeyCode.D)
	local sHeld = UserInputService:IsKeyDown(Enum.KeyCode.S)
	if aHeld then
		rotatedCFrame = CFrame.Angles(0, math.rad(1), 0)
	elseif dHeld then
		rotatedCFrame = CFrame.Angles(0, math.rad(-1), 0)

	end
	
	aboveMech = workspace.Mech.Torso.OrientBlockPlacement.WorldPosition

	orientBlock.CFrame = CFrame.fromMatrix(aboveMech,newRightSide,hitNormal)*rotatedCFrame

wait()
end



So at this point, I’ve been continuously experimenting, nothing seems to work and I’m just about on the verge of giving up. Here’s the place file for anyone interested. Perhaps I’ve messed up some of my calculations? I’m not too sure.

Test.rbxl (65.3 KB)

Made it sorta work and jump off the ramp using a modified version of the aforementioned script. I used the aforementioned method of using align orientation, frames, and rays that are in the collision group such that they only hit the ground.

https://gyazo.com/315e9bb4e66d309c9ff089f4721bbeba

btw the usage of the car object was pretty cool. Anyways here is the rbxl file:
HoverTest.rbxl (67.7 KB)

1 Like