Scripting and Moding Tutorial ‐ Revisioned - Outerra/anteworld GitHub Wiki
Here, we show you how to make your model vehicle ready for game. Read this after having your model already imported as an asset. INSERT LINK This is what we need to configure in order to make the model ready:
- Set physics to vehicle
- Create a script
- Set up the wheels
- Configure movement of the vehicle
- Set up the lights of the vehicle
- Set up the sounds
- Miscellaneous
1. Set physics (pre-configuration)
After importing the model, the game cannot tell whether you imported a vehicle, or a simple asset. In step 1, all we have to do, is to go to the .objdef file (which the game automatically creates after using the asset importer, it is located in INSERT ADDRESS). In there set physics
to "vehicle"
.
This simple step marks the imported object as a vehicle. Now we can set up the rest.
This is what the .objdef file should look like:
{
"obj" : "example",
"matlib" : "example",
"physics" : "vehicle",
"script" : "",
"description" : "",
"parameters" : "",
"parts" : "",
"tags" : ""
}
2. Create a script
Every vehicle needs its own script. A script is a code which tells the game how the vehicle should work within the world. And what properties it has. For example, in the script, you can find what is the top speed, which objects are the wheels and so on.
Add a JavaScript file to your folder and paste this code in it:
function init_chassis(param) {
return {
mass: 1120.0,
com: {
x: 0.0,
y: -0.2,
z: 0.3
},
};
}
function init_vehicle() {}
function update_frame(dt, engine, brake, steering, parking) {}
*If you don't know how to create a JavaScript file, you can steal one from Outerra World Sandbox\prg\game\mods\example_models_js\packages\tutorial_car_js
- accessible from Steam Library (right-click on Outerra game, select Manage
, then Browse local files
. ).
This script contains all three base functions a vehicle needs to work in Outerra. For basic use, you don't need to understand them more deeply, but if you want, here you go HERE.
- In
init_chassis
you can set the mass to whatever your vehicle weights. Default value is1000kg
. - Note that all three functions need to be in the script, otherwise the vehicle won't work.
- After you finished this, save the file and link it in the .objdef file. For example if your script is called car.js, this is what it should look like:
{
"obj" : "example",
"matlib" : "example",
"physics" : "vehicle",
"script" : "car.js",
"description" : "",
"parameters" : "",
"parts" : "",
"tags" : ""
}
If you did these two steps correctly, you will be able to find your vehicle in F3 vehicle spawner and spawn it. So far you will not be able to move it.
Example: Spawing the bus_double_joint example vehicle.
3. Set up the wheels
By now, you can spawn the vehicle in-game, you can even enter it, but it will not work as the game cannot detect any wheels yet. In this step we fix that.
Wheels are added by using add_wheel
. You need to add each wheel separately. The function requires two arguments: the name of the wheel object and a set of parameters:
let wheel_params = {
radius: 0.31515,
width: 0.2,
suspension_max: 0.1,
suspension_min: -0.04,
suspension_stiffness: 50.0,
damping_compression: 0.4,
damping_relaxation: 0.12,
grip: 1,
};
This is a set of technical parameters a wheel can have. Here INSERT LINK you can view what each of them means. But if you want to just do something quick and simple, the main thing you need to do is to set the radius and minimal and maximal suspension. If the radius is off, the vehicle will either be levitating or underground. Radius is in meters. You can either measure the radius in a 3D modeling software, or guess it, look at the vehicle in-game and see if it is off.. and then try again. Suspension dictates how far up and down the vehicle can move.
Add Wheels
Once you set the parameters, you can now add the wheels one by one. This is how you call the function:
wheels.FLwheel = this.add_wheel('wheel_l0', wheel_params); //front left wheel (will have ID 0)
wheels.FRwheel = this.add_wheel('wheel_r0', wheel_params); //front right wheel (will have ID 1)
wheels.RLwheel = this.add_wheel('wheel_l1', wheel_params); //rear left wheel (will have ID 2)
wheels.RRwheel = this.add_wheel('wheel_r1', wheel_params); //rear right wheel (will have ID 3)
Note that 'wheel_l0'
is how the wheel object is called in the example car's obj file. If you are doing it with your own, name it according to your wheel's name. FLwheel is the new name inside the script, you can name it anyhow you want. You do not need to be bothered about IDs, but if you care INSERT LINK.
If you are importing for example a tractor, which has multiple wheels of different sizes, you will have to us add_wheel on the different wheels with different wheel parameters.