Making my hovercraft lean when turning

So I got the hovercraft working but now I wan’t it to lean when I turn and I just cannot get my head around it how it should work. I am working with raycasting like the roblox jeep and some modifications regarding acceleration and such.
Now I want it to lean when turning but I don’t know how. I tried to rotate the whole mesh but that didnt work out.
Any help is appreciated!

You can check it out yourself and maybe make it work!
hovercraft.rbxm (88.5 KB)

EDIT: NEW PROBLEM. Leaning is only visible to the client. not other players, check out my replay down below

5 Likes

I don’t totally understand. Are you trying to make turning to the left make the right side of the hovercraft go down?
What do you mean by leaning?

Imagine me turning right , then I want the left part of the hovercraft to go up a bit and the right side of the hovercraft down a bit, so its turned to an specific degree based on how “hard” I turn.

here is a good video showing what I want https://www.youtube.com/watch?v=kmOD9ia2n24
The vehicles is leaning when turning

All I got so far is this


its always keeping the same degree when turning, and I want it to turn based on if I turn left or right.
( sry for bad english, I am from germany )

Any help is helpful! Tried it with AngluarVelocity but didnt get it to work…

How are you turning the car? A BodyGyro could be used…

I linked the model aswell so you can check it out yourself :))
I am using bodygyro and bodyposition.
image

If you want, you can do something like this:

bodyGyro.CFrame = CFrame.new(your vars I imagine) * CFrame.Angles(math.rad(15), 0, 0)

I’m assuming you’re setting the cframe already so just multiply the new CFrame you’re making with the angles on the x-axis and that should turn the hovercraft in that direction. Just don’t forget to change the degrees with the turning.

hmm didnt quite catch where to put it.

while true do
game:GetService(“RunService”).Stepped:wait()
for i, part in pairs(car:GetChildren()) do
if part.Name == “Hover” then
UpdateThruster(part.Thruster)
end
end
if car.DriveSeat.Occupant then
local ratio = car.DriveSeat.Velocity.magnitude / stats.Speed.Value
car.EngineBlock.Running.Pitch = 1 + ratio / 4
bodyPosition.MaxForce = Vector3.new()
bodyGyro.MaxTorque = Vector3.new()
else
local hit, position, normal = Raycast.new(car.Chassis.Position, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)
if hit and hit.CanCollide then
bodyPosition.MaxForce = Vector3.new(mass / 5, math.huge, mass / 5)
bodyPosition.Position = (CFrame.new(position, position + normal) * CFrame.new(0, 0, -stats.Height.Value + 0.5)).p
bodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
–bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(-math.pi/2, 0, 0)
bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(math.rad(90), 0, 0)
else
bodyPosition.MaxForce = Vector3.new()
bodyGyro.MaxTorque = Vector3.new()
end
end
end

(Question: How do I format LUA code correctly? lol)

To properly format LUA code:

  1. use the ` key 3 times
  2. CTRL + C
  3. CTRL + SHIFT + V

Near the lower end of your script you have this:

bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(math.rad(90), 0, 0)

Well, now all you need to change is the “* CFrame.Angles()”

When you turn left, it should be CFrame.Angles(math.rad(90), 0, math.rad(5))
When you turn right, it should be CFrame.Angles(math.rad(90), 0, math.rad(-5))

Sorry about my first post, I messed up my axi.

okey, I’ll try it out a bit :))
Will write again sooner or later!

Instead of setting the CFrame to make this lean I set the Orientation of the body and it doesn’t interfere with the thrusters

Aight. I got it working that it leans left and right depending where I am turning but I can’t get the model to face in the right direction now.

code:

while true do
		game:GetService("RunService").Stepped:wait()
		local steerdir = script.Parent.DriveSeat.Steer
		for i, part in pairs(car:GetChildren()) do
			if part.Name == "Hover" then
				UpdateThruster(part.Thruster)
			end
		end
		--driving right
		if steerdir == 1 then
			script.Parent.MeshPart.Orientation = Vector3.new(0,180,15)
		elseif steerdir == -1 then
			script.Parent.MeshPart.Orientation = Vector3.new(0,180,-15)
		end
		
		if car.DriveSeat.Occupant then
			local ratio = car.DriveSeat.Velocity.magnitude / stats.Speed.Value
			car.EngineBlock.Running.Pitch = 1 + ratio / 4
			bodyPosition.MaxForce = Vector3.new()
			bodyGyro.MaxTorque = Vector3.new()
		else
			local hit, position, normal = Raycast.new(car.Chassis.Position, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)
			if hit and hit.CanCollide then
				bodyPosition.MaxForce = Vector3.new(mass / 5, math.huge, mass / 5)
				bodyPosition.Position = (CFrame.new(position, position + normal) * CFrame.new(0, 0, -stats.Height.Value + 0.5)).p
				bodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
				bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(-math.pi/2, 0, 0)
			else
				bodyPosition.MaxForce = Vector3.new()
				bodyGyro.MaxTorque = Vector3.new()
			end
		end
	end

Orientation intereferes with BodyGyro, at least thats what I’m seeing. Try using my method, maybe that’ll work better.

oh yeah.
Basically what I did was have the body and the chassis in the same position, so if the chassis was at position 0,0,0 the body would be also, that way on every frame I could set the body position to the chassis position without bothering with calculating the offset.

local bodyLean = 15
local function adjustBody()
    Body.Orientation = Vector3.new(Chassis.Orientation.X, Chassis.Orientation.Y, bodyLean * steerdir )
    Body.Position = Chassis.Position
end
1 Like

I got it working now! :))
Thank you guys so much, helped me out alot and I’ve learned something new.

code:

		game:GetService("RunService").Stepped:wait()
		
		
		local steerdir = script.Parent.DriveSeat.Steer
		local bodyLean = 15
		
		
local function adjustBody()
    mesh.Orientation = Vector3.new(chass.Orientation.X, chass.Orientation.Y, bodyLean * steerdir )
    mesh.Position = chass.Position
	print("EXECUTED")
end

		for i, part in pairs(car:GetChildren()) do
			if part.Name == "Hover" then
				UpdateThruster(part.Thruster)
			end
		end
		
--driving right
		if steerdir == 1 then
			adjustBody()
		elseif steerdir == -1 then
			adjustBody()
		elseif steerdir == 0 then
			
		end
		
		if car.DriveSeat.Occupant then
			local ratio = car.DriveSeat.Velocity.magnitude / stats.Speed.Value
			car.EngineBlock.Running.Pitch = 1 + ratio / 4
			bodyPosition.MaxForce = Vector3.new()
			bodyGyro.MaxTorque = Vector3.new()
		else
			local hit, position, normal = Raycast.new(car.Chassis.Position, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)

			if hit and hit.CanCollide then
				bodyPosition.MaxForce = Vector3.new(mass / 5, math.huge, mass / 5)
				bodyPosition.Position = (CFrame.new(position, position + normal) * CFrame.new(0, 0, -stats.Height.Value + 0.5)).p
				bodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
				bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(-math.pi/2, 0, 0)
					--driving right
		
			else
				bodyPosition.MaxForce = Vector3.new()
				bodyGyro.MaxTorque = Vector3.new()
			end
			
		
		end
		
		
	end


(just need to find out how to smooth it)

I tried using lerp but didn’t get any result so now I am trying tweenservice and it behaving weird.
It’s not getting the correct Z Orientation I believe


Fixed it myself. Kinda dumb from my side to tbh.
I simply had to change the properties from Rotation to Orientation, That’s it.
here:

local prop = { Orientation = Vector3.new(chass.Orientation.X,chass.Orientation.Y, bodyLean * steerdir)}

2 Likes

Alright. New problem I saw. I don’t know why I didnt think about it earlier.
Basicly the Hovercraft contains a script and a localscript which the client gets, basicly the system from the Roblox Jeep (white one).
If I insert my code into the while loop in the localscript, everything works. Only the client can see the leaning, not actually other players.
But I want it so other players can see your leaning aswell.
I tried to insert the code into the normal script but when I do that, Other players won’t see me moving for some reason, very weird.

Any ideas?