NcJump devlog #4
Back with a new devlog! This time I am going to talk about dynamic entities, and how everything is now destructible!
The easy stuff
While a static entity is not affected by physical forces thus does not move, a dynamic entity is affected by forces, so it can fall and can be pushed and pulled around. Thanks again to Box2D, implementing this was just a matter of setting the type of physics bodies to either
Another easy but important thing to add was a proper background to give to players’ eyes something more interesting to see than a boring solid color. For the moment, I have just added a static sprite, but I guess it would be nice to implement a fancy parallax scrolling effect in the future.
At this point, I realized that something was missing. Tiles and entities could be added and positioned freely in the scene and, as all normal people that like symmetry, I started wanting to destroy them, not by interacting through the editor, but as Mario does by punching (or hitting with his head?)!
Appetite for Destruction
Well, not every tile should be destructible, but some of them certainly could, and I supposed it could be a good idea to give this ability to the player.
I started by introducing a flag to determine whether a tile is destructible or not. Then I implemented a destruction listener, which is a Box2D contact listener, responsible of checking impulses generated from collisions between entities. When this impulse is big enough, both flags of the entities involved in a collision are checked and, if destructible, added to a list. This list is processed later when the actual destruction happens. It is important to note that should not be done in the previous step if you want to avoid errors while Box2D is still processing its update.
After tweaking the threshold for the impulse triggering destructions, last thing to do was to increase manually impulses when the collision involved a character punching. In technical words, when one of the entities is a character and the normal of the collision is close to
(0, -1) destruction is triggered for the other entity.
The result is really cool because not only do entities get destroyed after a collision with the main character, but they also get destroyed when heavy collisions happen between each other.
Leave a comment
Log in with itch.io to leave a comment.