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!