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

Author Topic: Best way to detect collision?  (Read 6010 times)

0 Members and 1 Guest are viewing this topic.

Hengad

  • Newbie
  • *
  • Posts: 19
    • View Profile
Best way to detect collision?
« on: August 31, 2015, 06:31:16 pm »
Hello.

First of all, I am probably going to start post questions to this forum frequently.

Then into my question:
I know there are multiple way to detect collision between 2 entities, but which is best (I mean fastest and most efficient) way to detect collision?

I have been using intersects() method, but with fast moving objects, it doesn't seem to be very accurate.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best way to detect collision?
« Reply #1 on: August 31, 2015, 06:34:29 pm »
There's no best way. The most accurate will most likely be the slowest, and the fastest will be the less precise. So it all depends on your specific needs... which you haven't told us ;)
Laurent Gomila - SFML developer

Hengad

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Best way to detect collision?
« Reply #2 on: August 31, 2015, 06:40:36 pm »
Both as much same time I guess? How do professional games do this? They are not slow at all and all collision detection is very accurate.

Satus

  • Guest
Re: Best way to detect collision?
« Reply #3 on: August 31, 2015, 06:47:15 pm »
They are not slow at all

They are, it's just your PC is fast enough for you not to notice it.  :)

Quote
I have been using intersects() method, but with fast moving objects, it doesn't seem to be very accurate.

Your objects are either very small or moving super fast. You didn't specify your conditions. Also check your framerate.

There are a lot of info on this topic, but you may find this links useful:
http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
http://www.metanetsoftware.com/technique/tutorialA.html
http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169
http://www.dyn4j.org/category/gamedev/collision-detection/

PS. I'm currently working on my collision detection kit for C++ for my own SFML-based game, so if you post some details I may be able to help you (or I may not  :D).
« Last Edit: August 31, 2015, 06:54:50 pm by Satus »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Best way to detect collision?
« Reply #4 on: August 31, 2015, 07:00:02 pm »
The prime optimization for collision detection between many entities is spatial partitioning. That should give you the needed keyword to research further on your own :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Hengad

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Best way to detect collision?
« Reply #5 on: August 31, 2015, 07:04:42 pm »
They are not slow at all

They are, it's just your PC is fast enough for you not to notice it.  :)

Well how could I do that effect? My computer is not very good, just average for playing games. But if they really are "slow" and made to be accurate, then I want same accuracy too.

Quote
Your objects are either very small or moving super fast. You didn't specify your conditions. Also check your framerate.

Well they are moving very fast, I wouldn't say super fast. You can still easily see it on window when moving, but yeah it's small.. Also, I have capped framerate to 60, but I am planning to implement one good game loop with sfml. I have seen tutorial about it for java, it uses interpolation, and probably best game loop for both slow and fast machines.

Quote
PS. I'm currently working on my collision detection kit for C++ for my own SFML-based game, so if you post some details I may be able to help you (or I may not  :D).

Well. I am not having any project going on, I'm just practising SFML and more about c++. But if you have some accurate detection, I am listening.

Edit:

Quote
The prime optimization for collision detection between many entities is spatial partitioning. That should give you the needed keyword to research further on your own :)

Thank you. I will search about it.
« Last Edit: August 31, 2015, 07:06:14 pm by Hengad »

Satus

  • Guest
Re: Best way to detect collision?
« Reply #6 on: August 31, 2015, 07:25:19 pm »
Well they are moving very fast, I wouldn't say super fast. You can still easily see it on window when moving, but yeah it's small..

Your objects are too fast and small so they go entirely through each other without overlapping. Read this question on se, it will give you some ideas: http://gamedev.stackexchange.com/questions/18604/how-do-i-handle-collision-detection-so-fast-objects-are-not-allowed-to-pass-thro

Quote
But if you have some accurate detection, I am listening.
My code is not very good and optimized for very fast moving small object, but it can detect convex&convex or convex&circle collision and return minimal translation vector. Though it does not support rotation yet.

Quote
Also, I have capped framerate to 60, but I am planning to implement one good game loop with sfml. I have seen tutorial about it for java, it uses interpolation, and probably best game loop for both slow and fast machines.

You will find this useful: http://gafferongames.com/game-physics/fix-your-timestep/
« Last Edit: August 31, 2015, 07:27:53 pm by Satus »

Hengad

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Best way to detect collision?
« Reply #7 on: August 31, 2015, 07:35:50 pm »
Quote
Your objects are too fast and small so they go entirely through each other without overlapping. Read this question on se, it will give you some ideas: http://gamedev.stackexchange.com/questions/18604/how-do-i-handle-collision-detection-so-fast-objects-are-not-allowed-to-pass-thro

Quote
You will find this useful: http://gafferongames.com/game-physics/fix-your-timestep/

I took a peek to your first link, that makes sense now. Your other link about timestep looks good but it's long so I read it later. Thank you for those.