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

4 comments
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
uhh. How would I d othat?
Can you add invisible walls at the edges of your map?
It won't work. Because I'm moving my player with CFramne it'll go right through the wall...