Thursday, March 7, 2013

Bumps, Not Banks

‹prev | My Chain | next›

It has been a very long time, but I am finally ready to have another go at my river rafting game. When last I played with this game, I had gotten it to a not-quite-working state and was certain to be too complex for inclusion in 3D Game Programming for Kids. It may still prove too complex to be included in the book, but I hope not. It would be a nice 3D game with reasonable physics. If I can pull it off, it may even be worthy of being the last game in the book.

The main problem that I was never able to solve to my satisfaction was joining different river segments. Working with smooth paths is doable in Three.js, but problematic in Physijs. Since I need physics in this game, I stuck with adding straight segments at 45° angles:

The river sides would eventually be invisible (though still with physical presence to keep the player's raft on the river). When the sides are visible however, it is obvious that the sides have a tendency to protrude into the river. This is even more pronounced should two segments be at 90° angles:

After a bit of fiddling, I think it best to drop the idea of making these river side bard banks. Instead, I can make them very short—the kind of thing that a raft can easily jump over if it hits it at too high a rate of speed:
function bank(length, z) {
  var width = 100
    , half = width / 2;

  var bank = new Physijs.BoxMesh(
    new THREE.CubeGeometry(length*.9, 10, width),
        new THREE.MeshNormalMaterial(), 0.2, 0.9
  // ...
  return bank;
This allows me to avoid some tricky math in the book while at the same time adding a bit more strategy to the game.

Except that the banks no longer work. I had originally added these in older versions of Physijs and Three.js. When I try to play the game now, the player's raft is passing right through the banks as if they are not there. I had solved this a while back, but the solution seems to have changed. Something to work on tomorrow.

Day #683

No comments:

Post a Comment