Tuesday, September 25, 2012

Developers Log. Prototype Date 22 - Abilities and Movement Controllers

The biggest woe of the week was finding out that our physics engine, JigLibX, is failing on the xbox. The .DLL was causing the xbox to crash. After an hour and a half of trying to fix it, I decided to switch physics engines. I could have left it, as it worked fine on the pc, but I really want to show the avatars performing the actions. So I bit the bullet and set off to change out the physics engine. Fortunately I had created a PhysicsBody class that served as a wrapper for the physics controls on the player (managing movement, gravity, dimensions, etc.) This was the only class I had to change, essentially changing where the wires are plugged in, to get the new engine to work. Unfortunately, I first tried Jitter, which didn't work so well, and so I finally settled on BEPU Physics. Third time is the charm.

On top of getting a shiny new physics engine, I decided to change movement from being directly contained within the Player class, to being inside of a MovementController. I then split this into 4 classes: GroundMovementController, AirMovementController, WallHangingMovementController, and WallRunningMovementController.

Each of these controllers constantly monitors when it should start applying movement to the player physics body. This prevents convoluted code within the player class, each condition requiring conditions and flags that would be must be switched on and off. Instead, each controller has clean and manageable code that uses the StateManager to detect when the player is against the wall, on the ground, in the air, or etc. Each controller also has its own stats for movement, how movement is changed (for example, on the ground the velocity is set each update, whereas the air controller preserves velocity, altering it only a fraction of the amount, thus preserving momentum, but still giving the player some control, but less than when on the ground.) This enables us to change mechanics for movement easily without effecting everything else, or wading through dozens of variables, each for the various conditions.

Lastly, I have implemented the DoubleJumpAbility, WallRunAbility, and WallHangAbility. I'm not finished with wall run just yet, and also need to add an ability for when the player wishes to pull himself up off of a ledge. Everything is going very smoothly following this architecture, and I feel I have been able to accomplish a lot in a short amount of time, which is absolutely necessary because I have so little time left before we demo the prototype :X

No comments:

Post a Comment