Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make my 2D Movement Script prevent players from going off map?

Asked by 2 years ago

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!

01UIS.InputBegan:Connect(function(input, GameProcessedEvent)
02    if input.KeyCode == Enum.KeyCode.D then
03        if HRP.CFrame ~= Border3.CFrame then
04            canMove = true
05            HRP.CFrame = HRP.CFrame * CFrame.new(10, 0, 0)
06        end
07        if HRP.CFrame == Border.CFrame then
08            canMove = false
09        end
10    elseif input.KeyCode == Enum.KeyCode.A then
11        HRP.CFrame = HRP.CFrame * CFrame.new(-10, 0, 0)
12        if HRP.CFrame == Border2.CFrame then
13            canMove = false
14        end
15    elseif input.KeyCode == Enum.KeyCode.W then
View all 29 lines...

(Yes, I have a variable for everything in the script, I just did not include them)

Thank you for your help!

-KoalaKrush

0
cant you just check if their positionj is larger than the map boundary, and if they're trying to increase it in that direction prevent the movement Wayyllon 170 — 2y
0
uhh. How would I d othat? KoalaKo_XD 27 — 2y
0
Can you add invisible walls at the edges of your map? T3_MasterGamer 2189 — 2y
0
It won't work. Because I'm moving my player with CFramne it'll go right through the wall... KoalaKo_XD 27 — 2y

Answer this question