Tuesday, July 3, 2012

Infiltrator part 26 - Circle 2D

The lack of feature additions in this episode can be attributed to the relentless chase of a particular bug which very effectively crunked up the kinaesthetics. Yes I just used the word kinaesthetics, get used to it. And go watch yourself some Errant Signal if you have no idea what I mean.

Anyway, lets start at the beginning. I've actually had this issue for a long time, ever since I added physics to Infiltrator. At the time I was too busy going "ZOMG PHYSICS!" to deal with it. In essence, I had this really awful wall bounce. I'll draw up some pictures along the way to help explain myself:


The left panel demonstrates the object situation and ship velocity. After collision with the wall, panel two is the resulting object situation and velocity. Originally I figured I just had elasticity up too high and casually added it to the bug list. When the time came to fix the bug however, it became immediately clear that there was a much deeper problem here.

First off, I already had zero elasticity setup. Second, there was absolutely no rhyme or reason to why the ship was deflecting the way it was. The direction of deflection made no sense, and neither did the fact that the velocity of the deflection was even greater than that of the impact. It was clear that this was merely the side effect of some deeper problem. It wasn't until I started dissecting the physics that I finally realized what the problem was. This is what I pictured happening in the physics engine:


This was what was really happening:


This was worsened by the fact that I was manually grabbing the body rotation and setting it to face the cursor, which was likely causing all kinds of problems. I ended up having to redesign the core engine to allow me to create objects that used circle bodies for physics instead of only boxes, but the result was the death of a long annoying bug. Fortunately, Box2D was cooperative and I was able to see this fix through to the end just in time to finish writing about it. ;)

     --LazerBlade

No comments:

Post a Comment