Skip to content

five-on-it / packages/sim/src/car-hits

packages/sim/src/car-hits ​

Cars against people on foot, after the physics step: every contact between a vehicle and a character not in one is an impact, taken from the speed at which the car closed on the person along the contact's normal, less what the person was getting away at, with the velocities they came in with (recorded just before the step by recordApproach; after it the solver has already pushed the person along at the car's speed, which as such is no bounce at all). A person running into a car (at a parked one's corner, on the way to its door) is stopped by it, never hit by it.

  • Closing faster than KNOCKDOWN_SPEED (20 km/h), on a person its driver may hurt (not a player in a safe zone, or in a game without player damage): a hit. It takes CAR_HIT_DAMAGE hit points per m/s of the closing speed above the knockdown speed, charged to the driver (a pedestrian dies at 35 km/h), knocks the person down (RAGDOLL_TICKS if it lives, KNOCKDOWN_TICKS if not) and throws it: off the car's surface along the normal at the car's speed there plus HIT_RESTITUTION of the closing speed, up at HIT_LIFT of it (the bumper takes the legs, the body goes up onto the bonnet and over), turning back over the car (HIT_SPIN) to come down lying.
  • A body already down that a moving car meets again and is not leaving (caught up with in the air, coming down on its bonnet, hit head on) goes over it, as a body does off a car that keeps going: up to clear the roof, and slowed to VAULT_SHARE of the car's speed along its way, so the car drives on under it and it comes down behind. Never carried along on its front, nor bounced along ahead of it.
  • A body lying on the ground (down, within LYING_HEIGHT of the ground under it, neither rising nor falling) is driven over: the cars' bodies pass over it (griefing.ts's setLying), as a car's would, instead of pushing it ahead along the road. In the air, or on a car's roof, it meets them again.

Whatever the person gains along the normal the car gives, at the contact point, so a hit slows the car by the momentum it hands on (a sedan loses about a metre per second throwing a pedestrian at 60 km/h). Anything slower is the person's own business: a car moving at all makes whoever it touches step aside (stepAsideFromCar, character.ts, before the step, so they slide off along its front instead of being pushed ahead).

Variables ​

Functions ​