So I got my cube to move but when the cube hits a wall, it floats and does this:
Also, when pressing 2 keys at once, it wouldn’t move.
local UserInputService = game:GetService("UserInputService")
local function moveCube(velocity)
local cube = PlayerCubes:FindFirstChild(player.Name)
if cube then
local LinearVelocity = cube:FindFirstChildWhichIsA("LinearVelocity")
if LinearVelocity then
LinearVelocity.VectorVelocity = velocity
end
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.W then
moveCube(Vector3.new(0,0,40))
elseif input.KeyCode == Enum.KeyCode.A then
moveCube(Vector3.new(40,0,0))
elseif input.KeyCode == Enum.KeyCode.S then
moveCube(Vector3.new(0,0,-40))
elseif input.KeyCode == Enum.KeyCode.D then
moveCube(Vector3.new(-40,0,0))
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.W then
moveCube(Vector3.new(0,0,0))
elseif input.KeyCode == Enum.KeyCode.A then
moveCube(Vector3.new(0,0,0))
elseif input.KeyCode == Enum.KeyCode.S then
moveCube(Vector3.new(0,0,0))
elseif input.KeyCode == Enum.KeyCode.D then
moveCube(Vector3.new(0,0,0))
end
end
end)