Why use a car object to control acceleration / fuel usage etc, when vehicle keys and bags on the player can do that for you?
Why not change or attach a sprite to the player model itself?
Cars, like doors, match to keys. Put all the code on the vehicle keys.
When you activate a key to get into a car, it runs a script to check proximity to a matching vehicle or car object.
The vehicle key then spawns a bag object on the player called 'trunk',
increases player carrying capacity accordingly, and makes the player invulnerable.
Everything in the car object which is really just a container like say, a dumpster with a vehicle sprite and loot table
is automatically transferred into the 'trunk' (bag) attached to the player.
Finally, the individual vehicle's sprite replaces or is attached /overlaps the player, and the
last of all, the original vehicle object is destroyed.
Make it a timed action that cancels / is undone if the player moves at all, to prevent exploits.
From here, fuel is just an object in the 'trunk' or a separate (bag) item in the inventory/equipped
to the player. Acceleration / handling / fuel consumption are all controlled by code attached
to the vehicle keys.
When the player presses a key to 'exit' the vehicle:
1. Spawn a matching vehicle object nearby.
2. Transfer contents of 'trunk' from player to vehicle object on ground
3. Remove 'trunk' from player bags
4. Make the player vulnerable again
5. Set player walk speed to normal
6. spawn in or transfer fuel equivalent to whatever is left in inventory / in 'vehicle'
7. Change the player sprite or model back to normal / destroy vehicle sprite attached to player
8. Set player carrying capacity back to normal
This mitigates having to constantly update the position of a container
at all, because it has the player essentially act as the container,
and all the code runs on objects in inventory.
If I'm wrong, or misunderstanding something, or this wouldn't work
for some reason, let me know. Maybe this could solve for problems with mp? What do you guys think?