✓ Accepted answer
Assuming your grid starts at (0,0,0) and ends at (0,40,24), I would add an if statement after each movement of the snake to check if it exceeds a particular coordinate. Here's an example that would disallow movement.
if part.CFrame.Y > 40 then
part.CFrame.Y = 40
elseif part.CFrame.Y < 0 then
part.CFrame.Y = 0
end
if part.CFrame.Z > 24 then
part.CFrame.Z = 24
elseif part.CFrame.Z < 0 then
part.CFrame.Z = 0
end
edit: try this
RunService.RenderStepped:Connect(function()
camera.CameraSubject = part
camera.CameraType = Enum.CameraType.Attach
local move = CFrame.new(0,0,0)
if down.W == true then
move = move * CFrame.new(0,0,-.5)
if part.CFrame.Z <= -11 then
move = move * CFrame.new(0,0,0)
end
end
if down.S == true then
move = move * CFrame.new(0,0,.5)
if part.CFrame.Z >= 11 then
move = move * CFrame.new(0,0,0)
end
end
if down.A == true then
move = move * CFrame.new(-.5,0,0)
if part.CFrame.X <= -19 then
move = move * CFrame.new(0,0,0)
end
end
if down.D == true then
move = move * CFrame.new(.5,0,0)
if part.CFrame.X >= 19 then
move = move * CFrame.new(0,0,0)
end
end
part.CFrame = part.CFrame * move
end)
1 comment
Worked! I had to change the second move line to .5 and -.5 respectively to make it stay in bounds. Thank you.