zero gravity
Key RequiredUniversal

zero gravity

Universal ScriptHatManHatMan 517 views 4.7K executesUpdated Oct 4, 2026
Unrated
00
Lua Script•169 lines (4101 chars)
-- LocalScript
-- StarterPlayer > StarterPlayerScripts

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")

-- SETTINGS
local SPEED = 50
local ACCELERATION = 3
local SPIN_POWER = 1

-- HUMANOID
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.AutoRotate = false
humanoid:ChangeState(Enum.HumanoidStateType.Physics)

for _, state in ipairs({
	Enum.HumanoidStateType.FallingDown,
	Enum.HumanoidStateType.Ragdoll,
	Enum.HumanoidStateType.GettingUp,
	Enum.HumanoidStateType.Jumping,
	Enum.HumanoidStateType.Climbing,
	Enum.HumanoidStateType.Freefall,
}) do
	humanoid:SetStateEnabled(state, false)
end

local animate = character:FindFirstChild("Animate")
if animate then
	animate.Disabled = true
end

-- ZERO GRAVITY
local attachment = Instance.new("Attachment")
attachment.Name = "ZeroGravityAttachment"
attachment.Parent = root

local gravityForce = Instance.new("VectorForce")
gravityForce.Name = "ZeroGravity"
gravityForce.Attachment0 = attachment
gravityForce.RelativeTo = Enum.ActuatorRelativeTo.World
gravityForce.ApplyAtCenterOfMass = true
gravityForce.Force = Vector3.new(
	0,
	root.AssemblyMass * workspace.Gravity,
	0
)
gravityForce.Parent = root

-- IDLE
local animator = humanoid:FindFirstChildOfClass("Animator")

if animator then
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://180435571"

	local idle = animator:LoadAnimation(animation)
	idle.Looped = true
	idle.Priority = Enum.AnimationPriority.Idle
	idle:Play()
end

-- INPUT
local keys = {
	W = false,
	A = false,
	S = false,
	D = false,
	Space = false,
	Ctrl = false
}

UserInputService.InputBegan:Connect(function(input, processed)
	if processed then return end

	if input.KeyCode == Enum.KeyCode.W then keys.W = true end
	if input.KeyCode == Enum.KeyCode.A then keys.A = true end
	if input.KeyCode == Enum.KeyCode.S then keys.S = true end
	if input.KeyCode == Enum.KeyCode.D then keys.D = true end
	if input.KeyCode == Enum.KeyCode.Space then keys.Space = true end
	if input.KeyCode == Enum.KeyCode.LeftControl then keys.Ctrl = true end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.W then keys.W = false end
	if input.KeyCode == Enum.KeyCode.A then keys.A = false end
	if input.KeyCode == Enum.KeyCode.S then keys.S = false end
	if input.KeyCode == Enum.KeyCode.D then keys.D = false end
	if input.KeyCode == Enum.KeyCode.Space then keys.Space = false end
	if input.KeyCode == Enum.KeyCode.LeftControl then keys.Ctrl = false end
end)

-- MOVEMENT
RunService.Heartbeat:Connect(function(dt)

	local camera = workspace.CurrentCamera
	if not camera then return end

	local movement = Vector3.zero

	if keys.W then
		movement += camera.CFrame.LookVector
	end

	if keys.S then
		movement -= camera.CFrame.LookVector
	end

	if keys.D then
		movement += camera.CFrame.RightVector
	end

	if keys.A then
		movement -= camera.CFrame.RightVector
	end

	if keys.Space then
		movement += Vector3.yAxis
	end

	if keys.Ctrl then
		movement -= Vector3.yAxis
	end

	if movement.Magnitude > 0 then

		movement = movement.Unit

		local targetVelocity = movement * SPEED
		local currentVelocity = root.AssemblyLinearVelocity

		-- VERY gentle control
		local difference = targetVelocity - currentVelocity
		local change = ACCELERATION * dt

		root.AssemblyLinearVelocity =
			currentVelocity + difference * change
	end
end)

-- RANDOM TUMBLING
task.spawn(function()

	while character.Parent do

		local randomSpin = Vector3.new(
			math.random(-100, 100) / 100,
			math.random(-100, 100) / 100,
			math.random(-100, 100) / 100
		)

		if randomSpin.Magnitude > 0.1 then
			randomSpin = randomSpin.Unit

			-- Merge with existing spin
			root.AssemblyAngularVelocity +=
				randomSpin * SPIN_POWER
		end

		task.wait(math.random(60, 180) / 100)
	end
end)

Features & Information

lets you fly around and get pushed by other players also has physics

Community Comments (1)

voltexvoltexOct 11, 2026

workspace.Gravity = 0, but ok

More Scripts for Universal Scripts