You are currently browsing the Racing category archives.

Waverunners Boat Damage

Posted by Atashi at 2014.08.14 17.04 in Racing

After a lot of back and forth about how the Swamp Racers and the SkiJets handle health and receive damage, I’ve reviewed and revised the code and the prims once and for all.

First off, SL physics is not perfect. I had made the front bumper smooth and small, so it only added a tiny bit to the boats’ length and so that it wouldn’t get caught on anything like gate poles or obstacles. After some extensive testing, I’ve discovered that SL physics was basically ignoring this prim about half the time!

In other words, if driver A hit driver B from behind, what should have happened was Driver A would be assessed 200% the damage points. The script checked what prim had registered the collision, and if it was the front bumper, the damage was doubled.

Easy and logical.

The problem is, about half the time, the script was told that the impact occured on the visible hull prim rather than the invisible bumper prim. WTF?!

Some of you may remember I had been testing ramming the dock, because on occasion I could get an entire jetski to pass through the dock? Same thing. Physics is not completely fucked up, but it is not completely trustworthy either.

The two options were, ditch the bumper and just register hits against the boat hull, or make the bumper less subtle and more prominent. The problem with the first option is, you’d get assessed double damage even if someone hit you from the side, if they hit you in the front half of the boat, because the hull prim is the whole front half of the boat. The problem with the second option is,  it sticks out further and has hard corners, so it might catch on something.

I’ve experimented for an hour or two, and I think the protruding bumper is passable, so that is the choice I went with. It now sticks out like a big round invisible ‘button’ on the front of the boat.  If you turn on View Transparent in the viewer, you can see it.

The other thing is, I’ve explained how the damage is calculated so many times, I don’t want to have to type it out any more. If it’s that important that you have to keep asking about it, write yourself a notecard or something.

To make it easier on myself, I’ve rewritten the damage event handler and I’ve made it really simple. When you collide with something, the faster you are going, the more damage you will take. It doesn’t matter what you collide with. It doesn’t matter if the thing you collide with is moving or not. And it doesn’t matter if ‘they hit you‘ or if ‘you hit them‘. Each boat assesses its own damage independently.

The only thing that affects the damage calculations is a) was the object you collided with another boat? b) did the collision involve your front bumper? or did the collision involve your rear bumper?

And now, here is the actual collision event handler, in all its scripty glory:

collision_start(integer n) {
  integer  score   = 0;
  integer  type    = llDetectedType(0);
  integer  hitPrim = llDetectedLinkNumber(0);
  float mySpeed = llVecMag(llGetVel());
  if(mySpeed > 20.0) {
    // above 20 is turbo
    score = 30;
  } else if(mySpeed > 15.0) {
    // 15-20 is top speed without turbo
    score = 20;
  } else if(mySpeed > 10.0) {
    // 10-15 is mid range speed
    score = 12;
  } else if(mySpeed > 5.0) {
    // 5 - 10 is during accelleration or coasting
    score = 6;
  } // below 5 m/s there is no damage
  if(type == 10) {
    // we've collided with something physical and scripted
    // it is probably another boat, so test which prim was hit
    // if it was a bumper, adjust damage accordingly
    if(hitPrim == linkAftBumper) {
      // someone hit us from behind, damage is reduced to 1/3
      score = score / 3;
    } else if(hitPrim == linkFrontBumper) {
      // we have rammed someone
      // we take triple damage
      score = score * 3;
    }
  }
  if(score > 0) {
    // some damage has been assessed, so make the 'hit' noise
    // then update the boat's health HUD
    llTriggerSound(soundImpact, 1.0);
    setDamage(score);
  }
}

This script is taken from the swamp boat. The skijet is identical, but the damage ‘scores’ are slightly lower.

In english, this is what it means:

Going at turbo, in a straight line, the swamp boat maxes out around 24 meters per second. You hit something, you will lose 30 health points.

Going at non-turbo, but in a straight line, the swamp boat maxes out around 17 or 18 meters per second. You hit something, you will lose 20 health points.

Going through some turns, or not quite up to full speed, you’re somewehre between 10 and 15 meters per second and you hit something, you will lose 12 health points.

Just starting to accellerate, or decellerating, during a hard turn perhaps, and you’re between 5 and 10 meters per second, you hit something and you will lose 6 health points.

Now if what you hit is another boat, and you hit them with the nose of your boat, all those numbers are TRIPLED!

So if you punch the turbo button and go roaring up the tunnel at 24 meters per second right into the back of someone’s boat, you are going to lose 90 points! POW!

For SkiJet afficionados, the damage calculation is like this:

  if(mySpeed > 20.0) {
    // above 20 is turbo
    score = 20;
  } else if(mySpeed > 15.0) {
    // 15-20 is top speed without turbo
    score = 12;
  } else if(mySpeed > 10.0) {
    // 10-15 is mid range speed
    score = 6;
  } else if(mySpeed > 5.0) {
    // 5 - 10 is during accelleration or coasting
    score = 3;
  } // below 5 m/s there is no damage

Everything else is identical, including TRIPLE DAMAGE for hitting with the nose of your boat.


TL;DR – I’ve rewritten the damage, I’ve changed the bumper prims to account for SL’s flakiness, and what I’ve written here is the last time I’m going to explain it all.