FiveM Findings #1: Allow players to fly through the windshield of a car

Hi Snails,

It’s time for a small series of ‘findings’, to share knowledge amongst the community.
In this rendition we will be looking at a single player script where drivers (and passengers) fly through the windshield of a car.

Luckily the FiveM devs already thought of this and have gracefully supplied with a way to enable this.
First and foremost, you need to enable it on a server wide basis. This is by adding

setr game_enableFlyThroughWindscreen true

to your server.cfg.

Configuration.

In addition, there has been a native added called SetFlyThroughWindscreenParams, which allows us to configure the triggers of getting ejected.

Before we do that, know the following things, that I’ve observed from brief testing:

  • This only works with frontal impacts with other vehicles
  • For a vehicle impact, it must be strong enough to break the windshield.
  • It also ejects players if they hit dynamic object, do not require the windshield to break.
  • It also ejects players if they hit entities like ped and animals, do not require the windshield to break.

Above is not configurable, getting ejected at very low speeds simply isn’t feasible because of these restrictions. On a side note, the eject speed or force isn’t configurable either, not the damage you receive from it.

Let’s look at the SetFlyThroughWindscreenParams native parameters:

vehMinSpeed
Assuming this is the speed you are required to travel to trigger an eject.

unkMinSpeed
Unknown, I suspect this is the oncoming vehicle’s speed you’re colliding with or this is the object variant for 'vehMinSpeed"

unkModifier
This seems to be the minDamage for objects, setting this really high won’t cause an eject when you hit entities or dynamic objects.

minDamage
Docs say “minDamage”, possible a value of how much one (or both?) vehicles need to sustain to trigger the eject, a meassure of how heavy the impact basically.

Changing these variables don’t seem to be particular effective, only minDamage for certain situations as shown below.

Enabling windscreen ejections:

By calling

SetFlyThroughWindscreenParams(0.0, 0.0, 0.0, 0.0)

Enables the behavior, possibly you don’t even need to call it.
NOTE Setting it to all 0’s will cause you to instant eject if you hit an dynamic object or entity, suggested is to use the default values and tweak from there.

The default values in decompiled script are:

SetFlyThroughWindscreenParams(35.0, 45.0, 17.0, 2000.0)

NOTE You just need to call SetFlyThroughWindscreenParams once, in my script I set the values upon vehicle spawn.

Enabling and disabling based on situation.

There are situations where you do not want to eject the driver or passenger.

This can easily enabled and disabled, by setting minDamage required to trigger it, for instance something really high won’t cause an ejection:

SetFlyThroughWindscreenParams(35.0, 45.0, 17.0, 99999999.0)

and vice versa to enable it again!


Random experiments, epilepsy warning ⚠️

Ejecting out of car when you have set all the values to zero.

Normal eject from a frontal collision


Hopefully you found this useful in some kind of way!

11 Likes

Fantastic findings, thanks for the work! Going to play around with this now and look at possible implementations.

Doing some testing on this, it seems to be only on impacts directly to the front or rear bumper of a car, when working on vehicles. Side impacts seem not to trigger.

Additionally, we’ve noticed in testing that the third modifier is some kind of threshold/multiplier, it seems the last number will allow flying out at hitting anything when set to 0.

If the vehicle has a ram bar or something other physical parts, they actually prevent this from working. For example, set everything to 0 and use the trophy truck, it will take 3 to 4 hard crashes before you fly out.

We’re going to do more testing, but more info about this would be useful.

It’s good to know that if you want to make a more punishing crash system, this native should be used in conjunction with the “standard” methods of seatbelt implementation that you find in seatbelt scripts in FiveM.

This native is useful for making impacts to world objects more punishing, so hitting street lights, traffic lights, etc is dangerous.

Presently needs some balance, as we feel there is some numbers (maybe some vehicle meta data) or natives that affect crashing between cars.

Also could be placebo, but we found setpedconfigflag 32 (CPED_CONFIG_FLAG_WillFlyThroughWindscreen = 32,) seems to improve the likelihood of this happening.

Does the fly through windshields native still work properly with current fivem builds. As I know the old seatbelt script I used GitHub - zfbx/zseatbelt: Seatbelt resource built for FiveM using a completely new method stopped working after a update was pushed as it couldn’t connect to API. Now the script doesn’t even work at all showing up in the active scripts on Tx on my current build which is 2944. I rewrote the code for the windshield parameters and config portion try integrate it with my seatbelt script but it still doesn’t work. The script GitHub - TFNRP/seatbelt: Seatbelt script for FiveM, with LEO detection we use doesn’t even have the windscreen code in it. So is windscreen just very outdated native or is there some game rule that needs be set as I tried the “setr game_enableFlyThroughWindscreen true” which doesn’t do anything. I know this script has something in it where speed will make you flyout and ragdoll but it doesn’t work for damage. Could something of changed over years or has having hit a certain amount damaged not been reason to fly out car for fivem?