# How to resolve this problem with an object's collider?

In my game there is an obj_maze:

The width of the maze is 10 pixels in all its extension.

In the game, the goal is to get the obj_Cube through the maze.

obj_Cube:

The obj_Cube is wider than the maze on purpose, to get a pixel exceeding all sides as the object runs.

There are also obj_Tubes. They are responsible for defining what position the obj_Cube should go in the intersections that exist in the maze.

The obj_Tubes also have an extra pixel to stand out from the maze.

I made this whole explanation, to make it easier to understand my problem.

When obj_Cube collides with obj_TubeX, its new direction will be defined by what you can imagine.

It turns out that this is done wrongly, detection happens early in the collision, as expected.

Stirring in the bounding box, I was able to correct the problem.

By doing this I get the obj_Cube go right or left correctly.

Now and when the obj_Cube does not come from below, but from the right or from the left? This collision certainly did not happen properly.

Here is an example of the obj_Cube from the right, with the bounding box I used earlier:

The collision is neither detected.

Believe me, I've tested numerous bounding box possibilities for both obj_TubeX and obj_Cube, so that all cases are resolved, but it's physically impossible.

(At least the way I'm trying)...

I also thought about having three equal sprites from each tube with different bounding boxes, but that would be extremely harder and coarser, making my game weigh a lot more.

Sorry for the bad English, I'm not English speaker. I had to use google translator to translate everything.

There is a much cleaner solution. Instead of editing bounding boxes, you can detect a collision with the tube and wait before it turns.

At 1, the box sets a timer for x frames. At 2, the timer runs out and the box turns.

• Could you tell me exactly how to do this? The function I could use. I think I can not use a timer because there are cubes with different speed. Jan 19, 2018 at 0:54
• Or just compare positions which will be way easier. Dec 28, 2018 at 6:24

In the collision event add the following code as a wrapper for the turning code:

if (box.x == other.x && box.y == other.y)//other is the tube being collided against { //insert turning code here }

Basically your issue is that you wanted collision to be a replacement for detecting position, and that will only be the case when you make the collision for both exactly one pixel. You could do that, but I wouldn't recommend it.

The solution I found to this problem was as follows:

Starting with obj_TubeX => I've changed your collision box:

I also modified the obj_Cube collision box (I passed the collision box to the bottom of obj_Cube.):

In order for the collision to happen correctly, whatever direction the obj_Cube comes from, just modify the obj_Cube rotation before it collides with the obj_TubeX. See below:

You can change the rotation of obj_Cube by adding an object that makes this change in rotation in the path between obj_Cube and obj_TubeX.

• This is certainly a convenient and simple solution. I like its simplicity. Dec 29, 2018 at 0:20