Hi scripters!
i have a custom mount that has a steering system, and a jump system. but whenever i jump, i get dismounted from the seat. I have turned off humanoid jumping when your on the seat, so it has to be with the seat moving. Is there any way to fix this?
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local remote = ReplicatedStorage:WaitForChild("CameraDirection")
RunService.RenderStepped:Connect(function()
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid.Sit then
local camera = workspace.CurrentCamera
local camDir = camera.CFrame.LookVector
local flat = Vector3.new(camDir.X, 0, camDir.Z)
if flat.Magnitude > 0.01 then
remote:FireServer(flat.Unit)
end
end
end)
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and not gameProcessed then
-- Fire a jump request to the server
remote:FireServer("Jump")
end
end)
client side code for the chicken
local seat = script.Parent
local model = seat.Parent
local root = model:WaitForChild("HumanoidRootPart")
local humanoid = model:WaitForChild("Humanoid")
local TweenService = game:GetService("TweenService")
humanoid.AutoRotate = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local remote = ReplicatedStorage:WaitForChild("CameraDirection")
local direction = Vector3.new(0, 0, 1)
-- Body Movers
local velocity = Instance.new("BodyVelocity")
velocity.MaxForce = Vector3.new(1e5, 0, 1e5)
velocity.P = 5000
velocity.Velocity = Vector3.zero
velocity.Parent = root
local gyro = Instance.new("BodyGyro")
gyro.MaxTorque = Vector3.new(0, 1e6, 0)
gyro.P = 4000
gyro.CFrame = root.CFrame
gyro.Parent = root
-- Update direction from camera
remote.OnServerEvent:Connect(function(player, data)
if typeof(data) == "Vector3" then
if data.Magnitude > 0.1 then
direction = data.Unit
end
elseif data == "Jump" then
if seat and seat:IsA("VehicleSeat") and seat.Occupant then
local jumpTween = TweenService:Create(
seat,
TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
{ CFrame = seat.CFrame + Vector3.new(0, 8, 0) }
)
local fallTween = TweenService:Create(
seat,
TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.In),
{ CFrame = seat.CFrame }
)
jumpTween:Play()
jumpTween.Completed:Connect(function()
fallTween:Play()
end)
end
end
end)
-- Movement Loop
RunService.Heartbeat:Connect(function()
if seat.Occupant then
local throttle = -seat.Throttle
local moveDir = Vector3.new(direction.X, 0, direction.Z)
local speed = 40
local facingDir = root.CFrame.LookVector
velocity.Velocity = Vector3.new(facingDir.X, 0, facingDir.Z) * throttle * speed
-- Smooth rotation
local _, currentYaw, _ = root.CFrame:ToEulerAnglesYXZ()
local targetYaw = math.atan2(moveDir.X, moveDir.Z)
local angleDiff = math.atan2(math.sin(targetYaw - currentYaw), math.cos(targetYaw - currentYaw))
local newYaw = currentYaw + angleDiff * 1.1
gyro.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, newYaw, 0)
else
velocity.Velocity = Vector3.zero
end
end)
server side chicken code^^