Any Idea how can i make this UI maze minigame??
I would suggest to hold mouse click on the cheese to move it but it could get some problems for mobile.
So you could maybe do arrow keybind inputs to move the cheese, and add 4 arrow buttons at the bottom of the Ui, so when clicking buttons or pressing input, move the cheese to the selected direction by some pixels.
For the walls collision, you could do a X position check for horizontal walls and Y position check for vertical walls, then if the cheese image is at -5 to +5 pixel position of the wall position then it mean the cheese hitted the wall so make it respawn at start position.
Mouse will be hard for mobile users you can make it basic controls W,A,S,D
I do love this part but dont have any idea how can i make the walls.
You mean, to script the wall hit ?
i dont really when them to restart if they hit the wall, i want them to stay inside the walls and not go over them
Oh, so you want a simple collision if i well understood, like the cheese can hit the wall but it don’t do anything, the cheese just can’t go through them, is it right?
yess “the cheese just can’t go through them, is it right?”
Alright so you can implement the check into the cheese movement function.
Like when pressing arrows to move the cheese, check if the cheese isn’t close to a wall on the direction you want it to move.
I don’t know how to explain it well, but here is a piece of code that might help you to understand.
Edit: the numbers are supposed to represent the cheese image size in pixels, to prevent the image borders collision as the position only reference the center of the image.
local HorizontalWalls = {} --Left to Right walls - check Up & Down movements (Y axis)
local VerticalWalls = {} --Up to Down walls - check Left & Right movements (X axis)
local function MoveCheese(Direction)
local CanMove = true
if Direction == "Up" or Direction == "Down" then
for _, Wall in pairs(HorizontalWalls) do
if Direction == "Down" and Wall.Position.Y > Cheese.Position.Y + 5 and Wall.Position.Y < Cheese.Position.Y + 6 then
CanMove = false --Can't go down, there is a wall
elseif Direction == "Up" and Wall.Position.Y > Cheese.Position.Y - 5 and Wall.Position.Y < Cheese.Position.Y - 6 then
CanMove = false --Can't go up, there is a wall
end
end
elseif Direction == "Left" or Direction == "Right" then
for _, Wall in pairs(VerticalWalls) do
if Direction == "Left" and Wall.Position.X > Cheese.Position.X + 5 and Wall.Position.X < Cheese.Position.X + 6 then
CanMove = false --Can't go left, there is a wall
elseif Direction == "Right" and Wall.Position.X > Cheese.Position.X - 5 and Wall.Position.X < Cheese.Position.X - 6 then
CanMove = false --Can't go right, there is a wall
end
end
end
if CanMove == true and Direction == "..." then
Cheese.Position += ...
end
end
MoveCheese("Left") --On Button/Input pressed
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.