You can write your topic however you want, but you need to answer these questions:
- 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.
- 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.
- 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!