Spellcaster Studios

Make it happen…

Argh, more precision bugs!

The days started great… Added the “grass” shader to OpenGL, and added the option to hide the UI (great for screenshots), and was adding something pretty cool: water splashes when the player jumps or falls into water.

screen522

In the process, I found another silly precision bug (that of course, manifests if I switch renderers): when the player holds the jump key while in the water, on OpenGL it behaves as expected, but on D3D it would hover above the water!

After a lot of debugging (hard to do, because it’s an interactive thing, which means that I can’t use breakpoints, and debugger doesn’t work well with rivers), I finally found out the issue: a jump can only be triggered when the following conditions are met:

  • Height above the ground is smaller than 10cm
  • Vertical speed is zero

 

So, when we jump, there’s a point where the vertical velocity is zero: when we’re at the apex of the jump… That meant that if there’s terrain just below 10cm, it will be ready for another jump! On OpenGL, the vertical velocity would never be zero (it would be very small before going to negative, because of gravity), but on D3D (that sets the floating point unit to work with less precision), the velocity was zero, so a new jump could be triggered if we were just above the water, which happened…

So I had to add a very ugly piece of code, which checks if the velocity is more than zero and if the gravity effect would turn it into zero, it will set it to a very small negative value, to stop it from triggering a jump…

Alternatively, I could try to change the gravity strength so that it wouldn’t happen (risky), or use doubles (would cause the floating point unit to shift between normal and double precision, which could cause a real decrease in FPS).

This way is very hacky, but it works fine…

Now listening to “Undertow” by “Tool”

Link of the Day: This script looks awful… I know the movie it will be awful… But I need to watch it:

Comment