0
I’m developing a game for learning using C++ with SDL2, and I want to check when my character touches the ground. For this I created the class "Collider", with the following function (adapted):
bool isCollinding (SDL_Rect a, SDL_Rect b)
{
if(a.x > b.x + b.w || // Esquerda de A a direita do lado direito de B
a.x + a.w < b.x || // Direita de A a esquerda do lado esquerdo de B
a.y > b.y + b.h || // Topo de A abaixo da base de B
a.y + a.h < b.y) // Base de A acima do topo de B
{
return 0;
}
return 1;
}
However, with this method, I can only know if it’s colliding, but I don’t know if it’s the bottom or whatever. How could I know if what is colliding is the bottom easily?
I was going to send you a link from a collision that I detect this, but then I remembered it’s circle with rectangle... and in Python, Tkinter. It matters?
– Jefferson Quesado
Usually, when my colleagues go to make a 2D game as an exercise, they put a Colisor (actually, Colisor mode
trigger
in Unity) at the bottom of the object, which simplifies the algorithm used to know where the impact comes from– Jefferson Quesado
Python interests me, but never worked with, so I have no knowledge of the subject. Using a Trigger it’s a good idea, I can try.
– Felipe Nascimento
Look for
colidiu
: https://github.com/jeffque/games-tk-breakout/blob/master/breakout/geometry.py– Jefferson Quesado
This solution I sent you on the link makes no use of
trigger
, Only the Bead and the Bead– Jefferson Quesado