Hello,
I have a 2D movement system for a game like Space Invaders, and I don't want the player to go off map. Does anyone know how I can do that? I already have a script, the movement works, but the player can still go off the map!
UIS.InputBegan:Connect(function(input, GameProcessedEvent) if input.KeyCode == Enum.KeyCode.D then if HRP.CFrame ~= Border3.CFrame then canMove = true HRP.CFrame = HRP.CFrame * CFrame.new(10, 0, 0) end if HRP.CFrame == Border.CFrame then canMove = false end elseif input.KeyCode == Enum.KeyCode.A then HRP.CFrame = HRP.CFrame * CFrame.new(-10, 0, 0) if HRP.CFrame == Border2.CFrame then canMove = false end elseif input.KeyCode == Enum.KeyCode.W then HRP.CFrame = HRP.CFrame * CFrame.new(0, 0, -10) if HRP.CFrame == Border1.CFrame then canMove = false end elseif input.KeyCode == Enum.KeyCode.S then if HRP.CFrame ~= Border.CFrame then canMove = true HRP.CFrame = HRP.CFrame * CFrame.new(0, 0, 10) end if HRP.CFrame == Border.CFrame then canMove = false end end end)
(Yes, I have a variable for everything in the script, I just did not include them)
Thank you for your help!
-KoalaKrush