DuckBall Devlog 007: Taking Off

After two months off for the holidays and new babies, DuckBall development continues! I’ve cleaned the spam out of the comments gutter, updated my project and the Flat Red Ball Engine (which actually released another new version just this week), and finally settled down to getting these Ducks to behave again. They are unruly.

This week’s video shows the result of me fixing the IsOnGround problem that I mentioned in the last update. Upon flapping their wings, Ducks were immediately being reclaimed by gravity, so it took a double-tap on the controller’s A-button to actually get them to take off. Using the debug text I was able to find that there were two things that were contributing to the problem:

1. The Activity() method, for the ducks was being called twice each turn. As a result, their IsOnGround variable was being checked twice, and their vertical velocity was being set to 0 twice. I was excited when I found this, but I should have figured out that this wasn’t the whole story since a double-tap on the controller could break the duck free from the ground. The problem couldn’t exist in a single frame (since a double-tap takes place over a minimum of two frames).

2. I remembered what Velocity really means. The Duck’s vertical movement that you see is a dance between negative vertical acceleration (gravity) and it’s vertical velocity. Flapping the duck’s wings sets their velocity to a positive number, which is slowly dragged down by gravity. When a duck is resting on a platform, it’s velocity is set to 0, but only if IsOnGround is true. When I was having a duck take off from the ground, I was only changing their velocity. Velocity is a change in position over time, so the duck’s position wasn’t changing the same frame that it was taking off. As a result it was still colliding with the ground that frame, so it was still considered IsOnGround, and so it’s velocity would be set back to 0.

Now flapping the duck’s wings not only changes their velocity, but also changes their position upward a very small amount so they are immediately in the air, and cannot be mistaken for being on the ground that frame. I don’t know how elegant a solution this is, but it’s invisible to the user and solves a problem I’ve been having for a long while, so I don’t care at this point. This is probably an open invitation for it to bite me in the ass down the road.

Next, I need to fix that walking through walls business. Yeah, not sure when that started…

This entry was posted in DuckBall, Video and tagged , , , , , . Bookmark the permalink.

Leave a Reply