- How this works., This works by getting the players move direction and applying velocity from that move direction to move the player.
Vector3.new(-1, 0, 1) * PLANE_SPEED
This includes the move direction and the “PLANE_SPEED” to determine the velocity.
2. Creating the script., This will be a local script created in StarterCharacterScripts First define our initial variables.
local playersService = game:GetService("Players");
local runService = game:GetService("RunService");
local player = playersService.LocalPlayer or playersService.PlayerAdded:Wait();
local character = player.Character or player.CharacterAdded:Wait();
local humanoid = character:WaitForChild("Humanoid");
local humanoidRootPart = character:WaitForChild("HumanoidRootPart");
We now need to create our key variables and create our linear velocity.
local ACCELERATION = 4; -- lower = smoother
local DECELERATION = 6; -- lower = smoother
local PLANE_SPEED = 16; -- like the humanoid walkspeed
local TARGET_PLANE_VELOCITY = Vector2.zero;
local linearVelocity = Instance.new("LinearVelocity", humanoidRootPart); -- parents to rootPart
linearVelocity.Attachment0 = humanoidRootPart:WaitForChild("RootAttachment");
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane;
linearVelocity.PrimaryTangentAxis = Vector3.new(1, 0, 0); -- these 2 lines make the plane target Vector3.new(x, 0, z)
linearVelocity.SecondaryTangentAxis = Vector3.new(0, 0, 1);
linearVelocity.MaxForce = 10000; -- change depending on use
Finally our renderstep function and died event to disconnect properly.
local movementRenderStep = runService.RenderStepped:Connect(function(deltaTime: number)
local moveDirection = humanoid.MoveDirection;
local planeMoveDirection = Vector2.new(moveDirection.X, moveDirection.Z); -- converts Vector3.new(a, 0, b) to Vector2.new(a,b)
TARGET_PLANE_VELOCITY = TARGET_PLANE_VELOCITY:Lerp(planeMoveDirection * PLANE_SPEED, (if moveDirection ~= Vector3.zero then ACCELERATION else DECELERATION) * deltaTime); -- performs if statement from moving and not moving.
linearVelocity.PlaneVelocity = TARGET_PLANE_VELOCITY;
humanoid.WalkSpeed = .01; -- to keep humanoid autoRotate active (we dont need walkSpeed.)
end)
-- died conenction.
humanoid.Died:Connect(function()
movementRenderStep:Disconnect();
end)
Now you have a simple Linear Velocity movement system to elevate your experience! This is compatible with R6 and R15 and is supported across all devices! (Mobile, PC, Console) This is the full repository.
local playersService = game:GetService("Players");
local runService = game:GetService("RunService");
local player = playersService.LocalPlayer or playersService.PlayerAdded:Wait();
local character = player.Character or player.CharacterAdded:Wait();
local humanoid = character:WaitForChild("Humanoid");
local humanoidRootPart = character:WaitForChild("HumanoidRootPart");
local ACCELERATION = 4; -- lower = smoother
local DECELERATION = 6; -- lower = smoother
local PLANE_SPEED = 16; -- like the humanoid walkspeed
local TARGET_PLANE_VELOCITY = Vector2.zero;
local linearVelocity = Instance.new("LinearVelocity", humanoidRootPart); -- parents to rootPart
linearVelocity.Attachment0 = humanoidRootPart:WaitForChild("RootAttachment");
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane;
linearVelocity.PrimaryTangentAxis = Vector3.new(1, 0, 0);
linearVelocity.SecondaryTangentAxis = Vector3.new(0, 0, 1);
linearVelocity.MaxForce = 10000;
local movementRenderStep = runService.RenderStepped:Connect(function(deltaTime: number)
local moveDirection = humanoid.MoveDirection;
local planeMoveDirection = Vector2.new(moveDirection.X, moveDirection.Z);
TARGET_PLANE_VELOCITY = TARGET_PLANE_VELOCITY:Lerp(planeMoveDirection * PLANE_SPEED, (if moveDirection ~= Vector3.zero then ACCELERATION else DECELERATION) * deltaTime);
linearVelocity.PlaneVelocity = TARGET_PLANE_VELOCITY;
humanoid.WalkSpeed = .01; -- to keep humanoid autoRotate active
end)
humanoid.Died:Connect(function()
movementRenderStep:Disconnect();
end)
Enjoy!