How to lock Y axis on vehicle

I’m having issues where players boats are able to jump/fly or fall through the map, and I am wanting to prevent their boat from doing any movement on the Y axis. Issues come from clipping with meshes, or climbing up meshes.

This is in a Heartbeat event

function BoatController:UpdateMovement(deltaTime)
	local MoveVector = self.ControlModule:GetMoveVector() -- Player controls
	
	script.Inputs.Forward.Value = MoveVector.Z <= -0.1 -- Forward -> -1 Y
	script.Inputs.Backward.Value = MoveVector.Z >= 0.1 -- Backward -> 1 Y
	script.Inputs.Right.Value = MoveVector.X >= 0.1 -- Right -> 1 X
	script.Inputs.Left.Value = MoveVector.X <= -0.1 -- Left -> -1 X
	
	if self.CurrentBoat then
		local NewDriveVector = Vector3.new(
			0,
			0,
			math.clamp(script.ForwardAmount.Value * script.SlowdownPercent.Value, -1, 1)
		)
		local BoatBaseCFrame = self.CurrentBoat.CFrame
		local TrueDirectionVector = BoatBaseCFrame:VectorToWorldSpace(NewDriveVector)
		local HorizontalVector = TrueDirectionVector * Vector3.new(1, 0, 1)
		
		local Speed = self.BoatMaxSpeed
		
		self.BodyVelocity.Velocity = HorizontalVector * Speed
		
		local Multiplier = math.sign(NewDriveVector.Z)
		
		self.BodyGyro.CFrame *= CFrame.Angles(0, math.rad((self.Turn / 10) * Vector3.new(0, 0, NewDriveVector.Z).Magnitude * Multiplier), 0)
	end
end

Using BodyVelocity and BodyGyro for movement.
image

1 Like