Hello.
I'm a new soul on these forums so let me first share a few words. I've been an amateur programmer for a long time and I've worked with many languages (mostly visual basic), however, I've recently settled with ANSI/ISO C/C++. I've always been fascinated by 2D platformer games and I've also taken interest in game development. I am looking to develop a game with some physics involved and I needed a physics engine for that. I could code one myself, but why not use existing solutions, eh? I heard about Box2D while browsing the GameDev forums and it appears to be a nifty little 2D engine, perfect for a 2D platformer game though I noticed it could use a few more features. So I took a pencil and brainstormed a number of my ideas down on paper that I'd like to share with you. I'll be listing some more ideas like this in the near future.
This is a RFC (request for comments) thread. Basically, the intention of this threads is to comment and discuss a number of features that may possibly get implemented into the engine in the future. I'll try to do my best to describe the idea(s) so feel free to comment. This particular thread is about semi-solid platforms and the possibility to get the feature implemented in Box2D (if it hasn't already - note that I've only checked out Box2D v2.0.1). If you've played any 2D platformer games then you are most likely familiar with the concept of semi-solid platforms (I'll use the term "SS" to refer to semi-solid). SS platforms are just like fully-solid platforms except that they don't collide from beneath, allowing you to jump through it from underneath and land ontop. Some games go a step further, allowing you to jump back down by holding eg. the down button and hitting jump at the same time. I found an existing thread here, but I'd like to take this concept further as I think it's a must-have for a 2D engine.
I've tried to come up with a decent concept... something that scales well with future development of Box2D eg. kinematic bodies (movers), but I got stuck in a few places. I'm guessing the proper place to perform code modifications are probably shapes, not bodies. Frankly, the most feasible place for semi-solid shapes are static bodies (probably movers too when they are implemented). How dynamic bodies containing SS shapes would perform is a topic to be discussed.
So let's attempt to define a semi-solid static shape:
From the top, the semi-solid platform appears just like a normal fully-solid platform (except maybe when a combination of keys is pressed to disable the collision against certain objects, allowing them to pass through). From the bottom, any collision checking against objects entering the shape is automatically disabled. There is also no collision while the body is inside a SS shape, allowing bodies to move freely through in any direction. Once an object fully emerges ontop of the platform and is no longer colliding with it, the collision kicks in and prevents it from entering the shape from that direction. This way a player can jump from underneath and if he doesn't fully reach the top of the platform, he falls back down and there is no collision... meaning you won't get stuck in the middle of the semi-solid shape, should you not reach the top. There is one problem here - the concave shape groups. What if the whole concave shape group is supposed to be a SS platform? Objects may pass through only half-way before changing direction back down due to gravity. This means they would get stuck somewhere in the middle.
This concept of upper and lower side of a shape is rather simple, but there's a problem. Box2D can change the world gravity at any time. So what happens when gravity suddenly shifts and now faces sideways? What happens, should the bodies disobey the world gravity and have their own local gravity implemented at some point in the future? How would semi-solid shapes behave now? How do we know which way is up and which is down and therefore which way to block bodies or let them pass through? Do we calculate it based on a gravity vector of the body? Does the collision with SS shapes even change to adapt to new gravity direction or should it remain unchanged?
Not a perfect solution, but my ides was to define a new gravity-independent direction vector (let's call it "DV") for each SS shape that specifies which way a shape should let objects pass though. Just like a diode which passes the electric current in one direction no matter how you rotate the circuit. If an object is traveling at a direction that is greater than DV - 90° and lesser than DV + 90°, it will pass through the SS shape (collision will be disabled). If the same object hits the semi-solid shape from any other direction (lesser than DV - 90° or greater than DV + 90°), then it collides with the shape.
Looking into the future, I tend to ask myself a lot of questions. Suppose we have now implemented movers (kinematic bodies) in Box2D. We have a rotating mover in our level. How do we treat the case where a player wants to jump ontop of such SS body from underneath? What happens to the DV - does it still point to the original direction or does it rotate along with the body? If we use the former approach, it solves our problem, but may introduce a new one eg. what if we want the vector to rotate along? The latter approach lets us rotate the DV along the body, but by doing so it screws up the platform. Maybe the solution should be to have DV modified to automatically point in the opposite direction of gravity at each timestep. Again, something to be toughly discussed.
There, this pretty much sums up my ideas about SS platforms. I have tons of other ideas down on paper and I'll be making a few more writeups such as this one on various topics as I have time. But for now... please comment and discuss. Thanks.
Regards,
Copper
I'm a new soul on these forums so let me first share a few words. I've been an amateur programmer for a long time and I've worked with many languages (mostly visual basic), however, I've recently settled with ANSI/ISO C/C++. I've always been fascinated by 2D platformer games and I've also taken interest in game development. I am looking to develop a game with some physics involved and I needed a physics engine for that. I could code one myself, but why not use existing solutions, eh? I heard about Box2D while browsing the GameDev forums and it appears to be a nifty little 2D engine, perfect for a 2D platformer game though I noticed it could use a few more features. So I took a pencil and brainstormed a number of my ideas down on paper that I'd like to share with you. I'll be listing some more ideas like this in the near future.
This is a RFC (request for comments) thread. Basically, the intention of this threads is to comment and discuss a number of features that may possibly get implemented into the engine in the future. I'll try to do my best to describe the idea(s) so feel free to comment. This particular thread is about semi-solid platforms and the possibility to get the feature implemented in Box2D (if it hasn't already - note that I've only checked out Box2D v2.0.1). If you've played any 2D platformer games then you are most likely familiar with the concept of semi-solid platforms (I'll use the term "SS" to refer to semi-solid). SS platforms are just like fully-solid platforms except that they don't collide from beneath, allowing you to jump through it from underneath and land ontop. Some games go a step further, allowing you to jump back down by holding eg. the down button and hitting jump at the same time. I found an existing thread here, but I'd like to take this concept further as I think it's a must-have for a 2D engine.
I've tried to come up with a decent concept... something that scales well with future development of Box2D eg. kinematic bodies (movers), but I got stuck in a few places. I'm guessing the proper place to perform code modifications are probably shapes, not bodies. Frankly, the most feasible place for semi-solid shapes are static bodies (probably movers too when they are implemented). How dynamic bodies containing SS shapes would perform is a topic to be discussed.
So let's attempt to define a semi-solid static shape:
- Collides against objects from top only (rectangular shapes are easy, but what about more irregular shapes?)
- Collision is disabled from beneath (probably sideways too)
- Holding down some keys should disable the collision checking, allowing players to fall through. This would need some extra user coding and is probably outside the scope of Box2D.
From the top, the semi-solid platform appears just like a normal fully-solid platform (except maybe when a combination of keys is pressed to disable the collision against certain objects, allowing them to pass through). From the bottom, any collision checking against objects entering the shape is automatically disabled. There is also no collision while the body is inside a SS shape, allowing bodies to move freely through in any direction. Once an object fully emerges ontop of the platform and is no longer colliding with it, the collision kicks in and prevents it from entering the shape from that direction. This way a player can jump from underneath and if he doesn't fully reach the top of the platform, he falls back down and there is no collision... meaning you won't get stuck in the middle of the semi-solid shape, should you not reach the top. There is one problem here - the concave shape groups. What if the whole concave shape group is supposed to be a SS platform? Objects may pass through only half-way before changing direction back down due to gravity. This means they would get stuck somewhere in the middle.
This concept of upper and lower side of a shape is rather simple, but there's a problem. Box2D can change the world gravity at any time. So what happens when gravity suddenly shifts and now faces sideways? What happens, should the bodies disobey the world gravity and have their own local gravity implemented at some point in the future? How would semi-solid shapes behave now? How do we know which way is up and which is down and therefore which way to block bodies or let them pass through? Do we calculate it based on a gravity vector of the body? Does the collision with SS shapes even change to adapt to new gravity direction or should it remain unchanged?
Not a perfect solution, but my ides was to define a new gravity-independent direction vector (let's call it "DV") for each SS shape that specifies which way a shape should let objects pass though. Just like a diode which passes the electric current in one direction no matter how you rotate the circuit. If an object is traveling at a direction that is greater than DV - 90° and lesser than DV + 90°, it will pass through the SS shape (collision will be disabled). If the same object hits the semi-solid shape from any other direction (lesser than DV - 90° or greater than DV + 90°), then it collides with the shape.
Looking into the future, I tend to ask myself a lot of questions. Suppose we have now implemented movers (kinematic bodies) in Box2D. We have a rotating mover in our level. How do we treat the case where a player wants to jump ontop of such SS body from underneath? What happens to the DV - does it still point to the original direction or does it rotate along with the body? If we use the former approach, it solves our problem, but may introduce a new one eg. what if we want the vector to rotate along? The latter approach lets us rotate the DV along the body, but by doing so it screws up the platform. Maybe the solution should be to have DV modified to automatically point in the opposite direction of gravity at each timestep. Again, something to be toughly discussed.
There, this pretty much sums up my ideas about SS platforms. I have tons of other ideas down on paper and I'll be making a few more writeups such as this one on various topics as I have time. But for now... please comment and discuss. Thanks.
Regards,
Copper