local left = 0
local right = 0
local up = 0
local down = 0
local speed = 8
local focusMod = 1
move.OnServerEvent:Connect(function(player, index, value)
if type(value) == "number" then
if index == "Left" then
left = math.sign(value)
elseif index == "Right" then
right = math.sign(value)
elseif index == "Up" then
up = math.sign(value)
elseif index == "Down" then
down = math.sign(value)
end
end
end)
focus.OnServerEvent:Connect(function(player, focusing)
if focusing == true then
focusMod = 2
else
focusMod = 1
end
end)
RunService.Stepped:Connect(function(time, step)
local moveMod = Vector2.new(right - left, down - up).Unit
local realSpeed = speed / focusMod
playerObj.Position = playerObj.Position + UDim2.new(0, moveMod.X * realSpeed, 0, moveMod.Y * realSpeed)
end)
This is part of a control script for a “player” sprite. A Vector2 is used to calculate the direction the sprite will move in, and the result is normalized in case the player is moving diagonally.
However, if the sprite isn’t moving, this happens:
Is there a way to fix this?