Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting intersection direction/side.  (Read 2500 times)

0 Members and 1 Guest are viewing this topic.

fancode992

  • Newbie
  • *
  • Posts: 3
    • View Profile
Getting intersection direction/side.
« on: December 15, 2019, 08:11:33 pm »
Greetings,
As the title says, how can I get the side a sprite collides with another one? For example, I have an enumeration called "Direction" which includes north, south, west and east, a function shall return only one.

I am currently checking collision between two sprites via this code:
spritevar.getLocalBounds().intersects(spritevar2)

I am sorry for being so undescriptive. Thank you. :)

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Getting intersection direction/side.
« Reply #1 on: December 15, 2019, 10:54:05 pm »
you should use sf::Sprite::getGlobalbounds() instead of the local to test for intersects.
you may try manifold for detecting the collision from every directions up/down or left/right, here an excellent tutorial in this topic with examples:

http://trederia.blogspot.com/2016/02/2d-physics-101-pong.html

fancode992

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Getting intersection direction/side.
« Reply #2 on: December 17, 2019, 05:57:42 pm »
you should use sf::Sprite::getGlobalbounds() instead of the local to test for intersects.
you may try manifold for detecting the collision from every directions up/down or left/right, here an excellent tutorial in this topic with examples:

http://trederia.blogspot.com/2016/02/2d-physics-101-pong.html
Hello Mortal, thank you for helping me :).

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Getting intersection direction/side.
« Reply #3 on: December 17, 2019, 06:09:36 pm »
you most welcome  :)