Help with custom movement system

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)

maybe you could try messing around with AlignOrientation
i also had a cube game like this and thats what i did

Well you’re using Roblox physics and anytime a force is applied against an anchored part like that then it might bug out like your cube, I’d say if you want to use physics then add a BodyGyro or a AlignOrientation and set it up so the cube can’t rotate at all and if it tries the BodyGyro or AlignOrientation will have enough force that it’s not visible since it’s being set back. Otherwise, you can make a different more complex movement system where you are lerping (cframing) the cube in the direction it’s move and if a raycast detects a wall then it won’t let the cube move any further that way as you check on all sides (there’s probably an easier solution for this method).

I just disabled the AutoRotate in the humanoid.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.