Author Topic: A function for vehicle impact?  (Read 2974 times)


That i needed to tune down the impact speed that triggers the OnImpact, and that there are still things that i need to define so that the function works for the Apache.

That chunk of code does a few things more than just exploding on crash.

Code: [Select]
if(%obj.Apachegear == 2)
   %obj.speedlimit = 10;
  else
    %obj.speedlimit = 5;

Sets the speed at which something will explode. If landing gear is down(Apachegear ==2), then the vehicle should be allowed to crash at a faster speed without exploding. All in all you should just replace that section with

Code: [Select]
%obj.speedlimit = 5;
or whatever you want the minimum explode speed to be at since you may not have landing gears in your helicopter.

Also,

Code: [Select]
else if(%obj.speed < %obj.speedlimit)
defines what happens if the vehicle crashes but at a speed lower than the minimum explode speed. In this case, it applies 10 damage


So here is the bear minimum for this code without all those features and minimum explode speed set to 5.

Code: [Select]
function ApacheVehicle::onImpact(%this,%obj,%data)
{
%speed = vectorLen(%obj.getVelocity());

    %obj.speedlimit = 5;

  if(%obj.speed > %obj.speedlimit )
  {
    if(%obj.destroyed)
      return;
    %obj.setDamageLevel(0);
    %obj.destroyed = 1;
    %obj.finalexplosion();

    %obj.schedule(10,"delete");
    if(isObject(%obj.spawnBrick.client.minigame))
      %respawn = %obj.spawnBrick.client.minigame.vehicleReSpawnTime;
    %obj.spawnBrick.schedule(%respawn+1000,"spawnVehicle");
  }


}
« Last Edit: December 03, 2014, 06:56:13 PM by Str4tofortress »

It'd be better to apply damage based on how fast they hit using a lerp, by the way.

Code: [Select]
%damage = ((%obj.speed - %this.minImpactSpeed)/(%obj.speedlimit - %this.minImpactSpeed)) * 100;

Also, with that code you can set the minimum impact speed to whatever you want damage to start at, then define the speed to kill it with %obj.speedlimit.
« Last Edit: December 03, 2014, 09:22:03 PM by $trinick »