Was able to implement basic character movement although I got completely stuck on how to implement conditional character jumping (ie. character can only jump if he's on a surface). I originally tried to have a sensor attached to the bottom of the character object, but that required a separate contact listener check. I actually implemented this method, but it turns out that a contact only registers for the first time, so after the character collided with the game world, the boolean isOnGround would become false (since I set it to false every time step but expected it to become true on every time step due to a collision detection). I then looked online and found out from iForce2d that one could use a prismatic joint between the legs and the body and use motor speed to push the legs down and propel the body upwards. Unfortunately, when I tried this method, the motor wouldn't work at all no matter what I tried. Even though I spent a lot of time trying to get conditional character jumping to work, I only have the basic jump whenever framework "working" right now.
I also worked on having a hand position. I also tried two different ways, but in the end I settled on having a hand position be calculated on every mouse move, and for the position to always be at a WIDTH*2 distance from the character's body. I tested this and it works currently.
I'm hoping to work on penetrative projectiles tomorrow and to finish the conditional jumping as well.
In my Box2D platformer engine, I use the foot sensor approach, and keep a counter of the number of live contacts on the foot sensor, incrementing every BeginContact that involves the sensor, and decrementing on every such EndContact. Then isOnGround is just checking if the counter is positive.
ReplyDelete