Recommendations on approaching 2D collisions in a top-down RPG.
8 replies, posted
Right now I'm working on an experimental procedural RPG that revolves around generating content dynamically and using genetic algorithm to create completely emergent gameplay. So you can see that I really want to focus on these experimental aspects before I care too much about how the game will look.
I decided I to write the engine using SFML, a 2D library set. So its going to be the classic top down RPG type gameplay for now, my question is how can I handle 2D collisions? I have no experience in writing my own collisions but would like to be able to implement them.
I'm aware of libraries like Box2D and whatnot but those seem a bit over the top for my simple needs. All I need is a 2D collision system that I can do fast path finding in and supports WASD movement.
My options seem to be I make my own or I use some library of which I know none of currently. Would it be difficult and time consuming to create my own collision system?
Use bounding boxes to detect actual collisions (I don't think you need anything more precise), then quadtree the fuck out of it to not test against every other entity in the world. Implement A* for path finding.
You could also try to find a library, but writing this sort of stuff makes a good programming exercise.
It isn't very hard to implement collision detection, you could take a look at one of these :
[url]http://www.gamedev.net/reference/list.asp?categoryid=45#199[/url]
And indeed, use bounding boxes and try quadtrees later, cause it seems you are still a beginner since you don't even know how simple collision detection is.
I haven't got experience with SFML or anything like that but can tell you how I would write my own in OpenGL.
For something simple where realistic collisions are not needed, that is also computationally fast bounding circles are probably the easiest (although most people that are experienced with collision detection will disagree as it is very imprecise). Basically just have a check so if the character in question gets within a certain distance of another character's circle or a wall collide.
You can also do bounding boxes which is similar apart from instead of a circle you have a box around each thing (done by finding the largest and smallest x and y values). Once you have bounding boxes you can do AABB and OBB collision but they are probably more complex than you need.
The other thing to think of is what happens once they collide, you can work out the angle the character was going towards the object at (easily done by using which of the wasd keys were pressed down) and then working out how fast the character was moving and working out which way the character would be 'bounced'.
Is that the sort of thing you wanted to know?
Okay so I guess creating my own would be the best choice here. Looks like bounding boxes and quad trees are the way to go.
[QUOTE=quincy18;26606158]It isn't very hard to implement collision detection, you could take a look at one of these :
[url]http://www.gamedev.net/reference/list.asp?categoryid=45#199[/url]
And indeed, use bounding boxes and try quadtrees later, cause it seems you are still a beginner since you don't even know how simple collision detection is.[/QUOTE]
Cool hopefully that website will teach me how to write the kind of collisions I need. I'll read it then but does it have anything about quadtrees and perhaps A*?
[QUOTE=Mutex;26606985]Cool hopefully that website will teach me how to write the kind of collisions I need. I'll read it then but does it have anything about quadtrees and perhaps A*?[/QUOTE]
Wikipedia describes A* quite well, including some pseudocode: [url]http://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode[/url]
And here's a general primer on quadtrees: [url]http://www.kyleschouviller.com/wsuxna/quadtree-source-included/[/url]
[QUOTE=Mutex;26606985]Okay so I guess creating my own would be the best choice here. Looks like bounding boxes and quad trees are the way to go.
Cool hopefully that website will teach me how to write the kind of collisions I need. I'll read it then but does it have anything about quadtrees and perhaps A*?[/QUOTE]
You should check out the gamedev site :
[url]http://www.gamedev.net/reference/[/url]
contains general reference to many subjects
Theres a slight problem in bounding boxes in that objects which are small, and moving fast may not collide with other objects
if your not using lua then why should i help you?
on a more serious note, your sfml-type library may have a function or something for collision
Sorry, you need to Log In to post a reply to this thread.