Tilt while character flying

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

So i have a flight module, and im trying to add a tilt feature to it where if the player turns then the character will do a tilt in that direction but im lost on how to do that part.

  1. What is the issue? Include screenshots / videos if possible!

the issue is right now when the character turns the whole body just turns but i want to do more of a tilt as seen in the video.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

ive tried eveything that i can think of and i know it has something to do with body gyro but im not sure on what formula (if there is any) to do for the tilt process, ive looked everywhere. Below is the initialize function of the flight system.

function FlightSystem.Initialize()
	-- Variables for gradual acceleration
	local maxSpeed = 90
	local accelerationRate = 50 -- Adjust to control acceleration rate

	-- Helper function to calculate move direction
	local function calculateMoveDirection(camera)
		local moveDir = humanoid.MoveDirection
		if moveDir == Vector3.zero then return moveDir end

		local relativeDirection = (camera.CFrame * CFrame.new((CFrame.new(camera.CFrame.p, camera.CFrame.p + Vector3.new(camera.CFrame.lookVector.x, 0, camera.CFrame.lookVector.z)):VectorToObjectSpace(moveDir)))).p - camera.CFrame.p
		return relativeDirection == Vector3.zero and relativeDirection or relativeDirection.unit
	end

	-- Flying behavior
	local currentTween -- To track ongoing tweens
	local tweenInfo = TweenInfo.new(0.01, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)

	local FlightRun = RunService.PreSimulation:Connect(function()
		if flying then
			humanoid:ChangeState(Enum.HumanoidStateType.Physics)

			-- Calculate move direction
			local moveDirection = calculateMoveDirection(workspace.CurrentCamera)
			if moveDirection == Vector3.zero then
				flyMoving.Value = false
			else
				flyMoving.Value = true
			end

			-- Gradually increase speed
			if currentSpeed < maxSpeed then
				currentSpeed = math.min(currentSpeed + accelerationRate * game:GetService("RunService").PreSimulation:Wait(), maxSpeed)
			end

			-- Calculate tilt based on crunchy movement and rotation 
			if moveDirection.Magnitude > 0 then
				local relativeTurnDirection = workspace.CurrentCamera.CFrame.RightVector:Dot(moveDirection)
			end

			-- Update BodyGyro to align with movement direction and tilt
			local targetCFrame
			if moveDirection.Magnitude > 0 then
				targetCFrame = CFrame.new(Vector3.zero, moveDirection) -- Align to move direction
			else
				targetCFrame = workspace.CurrentCamera.CFrame -- Default to camera direction
			end


			local goal = { CFrame = CFrame.new(humanoidRootPart.Position) * (targetCFrame.Rotation) }

			if currentTween then
				currentTween:Cancel() -- Cancel any existing tween
			end

			currentTween = TweenService:Create(bodyGyro, tweenInfo, goal)
			currentTween:Play()

			-- Apply gradual velocity
			bodyVelocity.Velocity = moveDirection * currentSpeed
		else
			hoverAnimation:Stop()
			flyAnimation:Stop()
			windSound:Stop()
		end
	end)

	--Flying Checks
	humanoid:GetPropertyChangedSignal("Health"):Connect(function()
		if humanoid.Health <= 0 then
			FlightRun:Disconnect()
			windSound.Volume = 0
		end
	end)

	-- FlyMoving state change with FOV tweening
	flyMoving.Changed:Connect(function(isMoving)
		if isMoving then

			hoverAnimation:Stop()
			flyAnimation:Play()

			windSound.Volume = 0.3
			if not windSound.IsPlaying then
				windSound:Play()
			end
		else

			flyAnimation:Stop()
			hoverAnimation:Play()

			windSound.Volume = 0.2
			if not windSound.IsPlaying then
				windSound:Play()
			end
		end
	end)

end

any feedback or help would be greatly appreciated! :grinning:

1 Like

The characters tilt when flying because the Humanoid’s physics reacts to movement inputs and gravity.

2 Likes
game:GetService("RunService").RenderStepped:Connect(function()
    local currentCFrame = humanoidRootPart.CFrame
    humanoidRootPart.CFrame = CFrame.new(currentCFrame.Position) * CFrame.Angles(0, currentCFrame:ToOrientation())
end)

This should fix the problem.

see with that it doesnt tilt it just moves the player itself, im trying to achieve something like this like how it moves in the direction of the mouse turn.

https://gyazo.com/8787cc8b5e3aa05bdd66f46a95df18ee

there should be a motor6d in the humanoidrootpart called something like “root hip”. make that rotate to follow the mouse’s position. i don’t know how to do it off of memory but there should be at least one tutorial to do it.