How to make my 2D Movement Script prevent players from going off map?
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!
01 | UIS.InputBegan:Connect( function (input, GameProcessedEvent) |
02 | if input.KeyCode = = Enum.KeyCode.D then |
03 | if HRP.CFrame ~ = Border 3. CFrame then |
05 | HRP.CFrame = HRP.CFrame * CFrame.new( 10 , 0 , 0 ) |
07 | if HRP.CFrame = = Border.CFrame then |
10 | elseif input.KeyCode = = Enum.KeyCode.A then |
11 | HRP.CFrame = HRP.CFrame * CFrame.new(- 10 , 0 , 0 ) |
12 | if HRP.CFrame = = Border 2. CFrame then |
15 | elseif input.KeyCode = = Enum.KeyCode.W then |
16 | HRP.CFrame = HRP.CFrame * CFrame.new( 0 , 0 , - 10 ) |
17 | if HRP.CFrame = = Border 1. CFrame then |
20 | elseif input.KeyCode = = Enum.KeyCode.S then |
21 | if HRP.CFrame ~ = Border.CFrame then |
23 | HRP.CFrame = HRP.CFrame * CFrame.new( 0 , 0 , 10 ) |
25 | if HRP.CFrame = = Border.CFrame then |
(Yes, I have a variable for everything in the script, I just did not include them)
Thank you for your help!
-KoalaKrush