I have been making a game about pushing things, based on a grid-based system, purely out of GUI, and I cannot find a way to push multiple boxes at a time, all I get is the boxes stacking on top or below of other things, and to stop the player from moving when the object they are pushing is against an object that does not allow pushing.
I searched in the forums, and did not find anything useful, so I am going to put the part of the code for collision and pushing detection
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.Up and canmove == true then -- CanMove is for a cooldown to avoid GUI objects going everywhere
ping:FireServer() -- ping Is a RemoteEvent for other things
--[Collision check]--
local collisions = script.Parent.Parent:GetChildren() -- Script.Parent.Parent is the frame where all of the level is
for i = 1, #collisions do
local item = collisions[i]
if item.Position.X.Offset > script.Parent.Position.X.Offset - 1 and item.Position.X.Offset < script.Parent.Position.X.Offset + 1 and
item.Position.Y.Offset > script.Parent.Position.Y.Offset - (scale + 1) and item.Position.Y.Offset < script.Parent.Position.Y.Offset - (scale - 1) then -- This detects the objects aligned in a set Y and X position, their source point is the middle of the screen and the scale is set to multiples of 50 (script.Parent comes to be the character the player moves, that is an ImageLabel
if item.push.Value == false and item.stop.Value == true then
collided = true --Stops the script from moving the character after recieving a collision, this gets turned false at the end of the turn.
elseif item.push.Value == true then --[push] and [stop] are bool values inside imageLabels that define hitboxes of the crates
item:TweenPosition(UDim2.new(item.Position.X.Scale, item.Position.X.Offset, item.Position.Y.Scale, item.Position.Y.Offset - scale), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15) -- The character moving
end
end
end
If there are any suggestions, questions or alternate ways, let me know!