I made a local script to move the player and it works, but for some reason the movement is very jittery (See video). Any clue what the issue is? Not sure if this is the best way to do it.
Movement Script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local MOVE_FORWARD = "MoveForward"
local MOVE_BACKWARD = "MoveBackward"
local MOVE_SPEED = 750
local forwardPressed = false
local backwardPressed = false
function moveForward(_, inputState, _)
if inputState == Enum.UserInputState.Begin then
forwardPressed = true
elseif inputState == Enum.UserInputState.End then
forwardPressed = false
end
end
function moveBackward(_, inputState, _)
if inputState == Enum.UserInputState.Begin then
backwardPressed = true
elseif inputState == Enum.UserInputState.End then
backwardPressed = false
end
end
ContextActionService:BindAction(MOVE_FORWARD, moveForward, true, Enum.KeyCode.W)
ContextActionService:BindAction(MOVE_BACKWARD, moveBackward, true, Enum.KeyCode.S)
player.CharacterAdded:Connect(function()
local tank = player.Character
local root = tank.PrimaryPart
RunService.RenderStepped:Connect(function(delta)
local speedVector = root.CFrame.RightVector * MOVE_SPEED * delta
local velocity = Vector3.new()
if forwardPressed and not backwardPressed then
velocity = speedVector
elseif backwardPressed and not forwardPressed then
velocity = -speedVector
end
root.AssemblyLinearVelocity = Vector3.new(velocity.X, root.AssemblyLinearVelocity.Y, velocity.Z)
end)
end)
** You are now Level 1! **