+1 vote
by
edited by
Can I use the "Data Bus" to send realtime control data to the vehicle the player is driving? E.g. can I write a script to handle the accelerator and brake pedal inputs myself and somehow send that through Data Bus as the combined throttle/brake axis?

1 Answer

0 votes
by
edited by
 
Best answer

Yes, you can disable VPStandardInput and use VPVehicleToolkit component for that. It exposes a public API with the most commonly used features of a vehicle, including sending input data. The source code of VPVehicleToolkit is available for reference here:

https://vehiclephysics.com/components/vehicle-toolkit/

Additionally, you can use the VPVehicleToolkit source code as example on using the Data Bus for sending and retrieving data from the vehicle in your own scripts. More info on using the Data Bus:

https://vehiclephysics.com/advanced/databus-reference/

Note: The community Edition doesn't support custom add-ons derived from VehicleBehaviour, but you may use standard MonoBehaviour scripts with a reference to the vehicle.

by
I created a script named "VPStandardInput " and added all the sourcecode provided in the https://vehiclephysics.com/components/vehicle-toolkit/

This script is getting disabled automatically. when the game starts.
by
edited by
The VPVehicleToolkit component is already included in VPP. Simply add it to your vehicle ("Add Component" button in the Inspector), disable or remove the VPStandardInput component, and use the methods of VPVehicleToolkit from your own scritps. The source code in the website is provided as reference.

The reason your component is being disabled is that the Community Edition doesn't allow custom vehicle add-ons (VehicleBehaviour). You can use the provided vehicle add-ons only, and VPVehicleToolkit is already included among them.
by
Can you please explain how I can use the methods of VPVehicleToolkit from my script? I have added VPVehicleToolkit in my inspector of the vehicle and disabled the standard input. But in my script, how do I get the reference to the vehicle, so I can navigate it?
by
That's generic Unity programming. There are several ways depending on the specific context. A Google search for "unity calling functions from other scripts" brings a number of articles:
https://www.google.com/search?q=unity+calling+functions+from+other+scripts
...