SFML community forums
Help => Graphics => Topic started by: Hengad 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.
-
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 ;)
-
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.
-
They are not slow at all
They are, it's just your PC is fast enough for you not to notice it. :)
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).
-
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 :)
-
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.
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.
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:
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.
-
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
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.
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/
-
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
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.