0
\$\begingroup\$

In my game there is an obj_maze:

enter image description here

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

enter image description here

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

obj_Cube:

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

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

enter image description here

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:

enter image description here

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.

Thank you in advance!!!

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

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

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

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ Jan 19, 2018 at 0:54
  • \$\begingroup\$ Or just compare positions which will be way easier. \$\endgroup\$
    – user64742
    Dec 28, 2018 at 6:24
1
\$\begingroup\$

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 }

Adjust offsets accordingly.

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.

\$\endgroup\$
1
\$\begingroup\$

The solution I found to this problem was as follows:

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

enter image description here

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

enter image description here

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:

enter image description here

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This is certainly a convenient and simple solution. I like its simplicity. \$\endgroup\$
    – user64742
    Dec 29, 2018 at 0:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .