Lesson of the day: Don’t try and calculate an acceleration using a 1/60 snapshot

So today I was back heavily into physics and integration problems. I couldn’t work out what the hell was going on. Walked the dog, still no improvement. Then just before I headed out to Body Combat I dumped out some acceleration figures, these were all over the place. For an object that was supposed to be accelerating I was getting negative accelerations.

So came back from combat and had a closer look. If I stepped through it in the debugger, then all was good, problem with that was, it was using a bigger time step. That was the root of the issue. I was taking the position of an object, then ticking it through physics and then taking the position of it again. Using the two positions I was then generating a velocity by taking the distance moved and then dividing it by the time step. Then using the difference between two velocities multiplied by the time step to calculate the acceleration. The problem is if you look at an object that’s being integrated by a physics tick of 1/60 of a second it moves all over the place. It’s then made even worse by floating point errors and then multiplying back by inverse times. So in the end I just stored the velocity and used that, everything then worked fine. The good news is I now know what the problem is. The back news is I need to write a whole load more shit to get round it all.

I’ve been feeling a little bit under the weather all day, so having an early night with some hot lemon and probably watch a bit of crap tv on the iPad.

Leave a Reply

Your email address will not be published. Required fields are marked *