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
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.
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.
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)
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))
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
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
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
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 https://gyazo.com/565231ba72703dda1e80834752478984
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.