I’m making a Tetris style game and i have pretty much everything running smoothly, the only problem is if the current block hasn’t reached the bottom yet and there’s a block next to the current block and you move it to the side the other block is on, the current block will get stuck in the other block,
I’m using the collision to tell the blocks when to stop moving down so i can’t use it to detect if there’s a block to either side, how can i fix this?
Can you post a gif of the problem, and a screenshot of the events, it’s kind of hard to tell what is happening from your description. Have you tried using the separate objects event? I guess you could also use coordinates to check but this could get complicated.
Thank you, I guess in the events that handle collision you should also use the separate objects event. I think what would really help though is for the a and d key presses you should also include a condition checking if the current box is in collision with other boxes. I’m not entirely sure but it might be better to use forces instead of changing the actual x position, because this could bypass the separate objects event.
Thanks for the reply, however i cant have it check if the current box is in collision with the other boxes because the collision masks are all slightly thinner than the actual box sprite because if they werent the current box would stop when it slides past the other boxes despite having nothing below it. I also need it to change position instead of adding forces so that the boxes stay perfectly lined up with eachother
okay, tell me if I’m doing something wrong here, tried your advice, but it only seems to trigger with the first box and then that first box just passes through the floor and all the following boxes pass through and now two boxes are spawning for some reason?
i added a point on all the boxes calles stopCheck just below their collision box
Is only one box moving at a time? Is that what the CurrentBox variable is for? If so, move those events in the screen snip as subevents of an event with the condition that Boxes.CurrentBox is true
If there are multiple moving boxes, then shift those events as subevents of a For each instance of Boxes event.
I tried that, it stopped the boxes from moving when they reached the floor but for some reason the boxes stopped falling, unsure if the event wasn’t triggering or if they were just getting stuck on eachother
okay so I retried what you suggested and i also made it so only one kind of box can spawn to reduce any issues caused by the placement of the points.
for the most part it works, except now the boxes will fall through eachother and not stack
i think the problem is that its checking all instances of the box specifically for the point condition, so as long as one of them returns to true it will continue to do so, which is odd because the “current box” variable should be preventing that from happening
Hi. I think the issue is it’s filtering the objects with the “currentBox is true” So, it can only test against itself. An option would be to save the x,y, pick all of the Boxes and check if the x,y point is inside the Boxes. If found you would have to select all of the Boxes again and pick the object with the “currentBox is true” Boolean value because the is inside condition would pick the box below the box that’s falling.
Im a little bit confused. It filters with “current box is true” because then the only situation it should be happening with is the box where that variable is true, if its not true with the other boxes, then the code shouldn’t execute.
Also your alternative is confusing to me, can you explain it again please?
Firstly though, and as @Keith_1357 wrote, the issue you have here is that the first event filters the list of Boxes GDevelop works with to just one box. The second event tests if the point stopCheck is within the box. But it never will be, because it’s always outside of the box.
Ask yourself this - even if the conditions of the second event did include all the boxes, which box would the force action be used on? The box with the points that aren’t in another box, the box with CurrrentBox set to true, or the box that the point is not in (of which there will be multiple)?
As @Keith_1357 suggested, one way around this (and the way I’d use too) is:
The first event reduces the list to one box object.
The second event applies the subevent conditions to all the box objects. This is only for the event and subevents. That is the scope of the event’s conditions - it does not use all the objects for the following sibling event.
The final event applies the force to the object from the first /parent event, because that is the scope of the object list. It does not know about the conditions from the second event.
Yeah, it’s a bit convoluted, but I think it’ll work how you want it to.
I suppose i could try it but i still dont know why my code wouldnt work
From my understanding the whole point of having a point just below the current box was to test if there was a box below it. So if the point on the current box went inside one of the boxes that was already placed it would tell the current block to stop moving, set the currentBox variable to false and spawn another block where the currentBox variable was true, rinse, wash repeat.
I also don’t understand why it worked for the floor, but not the other boxes
But GDevelop does not have any other box in scope for that events and it’s subevents.
The first condition filters the list that GDevelop works with down to one specific box. GDvelop will only use that one box when you reference boxes in the event and sub events.
When you check if box.point(stopCheck) is within box, GDevelop will only check is the point is within the same box it belongs to because that is the only box it knows about for that event and subevents.
Because you have not filtered floor obejcts with a condition, so GDevelop checks all the floor objects.