Hi, i’m having a problem with this Part Movement system. Basically, i want to move a simple object with userInputService, and that’s fine, but the problem comes with collisions. I want the object to collide with other parts, but it just goes through everything… I tried setting a collision group to the object and the parts to collide with, but nothing. Could you guys help me please? It would be very appreciated !
Script: (StarterPlayerScripts)
local Input = game:GetService("UserInputService")
local cube = game.Workspace.Cube
local moveX = 0.5
local moveY = 0.5
local waitTime = 0.01
local inputLeft = script.inputLeft
local inputRight = script.inputRight
local inputUp = script.inputUp
local inputDown = script.inputDown
local left = false
local right = false
local up = false
local down = false
Input.InputBegan:Connect(function(input, gameProcessedEvent)
while wait() do
if Input:IsKeyDown(inputRight.Value) then
right = true
else
right = false
end
if Input:IsKeyDown(inputLeft.Value) then
left = true
else
left = false
end
if Input:IsKeyDown(inputUp.Value) then
up = true
else
up = false
end
if Input:IsKeyDown(inputDown.Value) then
down = true
else
down = false
end
end
end)
while wait(waitTime) do
cube.Orientation = Vector3.new(0, 0, 0)
if right == true then
cube.Position = Vector3.new(cube.Position.X + moveX, 2, cube.Position.Z)
end
if left == true then
cube.Position = Vector3.new(cube.Position.X - moveX, 2, cube.Position.Z)
end
if up == true then
cube.Position = Vector3.new(cube.Position.X, 2, cube.Position.Z - moveY)
end
if down == true then
cube.Position = Vector3.new(cube.Position.X, 2, cube.Position.Z + moveY)
end
end
Here’s a small video: