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:

  1. Set physics to vehicle
  2. Create a script
  3. Set up the wheels
  4. Configure movement of the vehicle
  5. Set up the lights of the vehicle
  6. Set up the sounds
  7. 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.

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.

In order to create a script the easy way, we are simply going to steal an already functioning script from a different model. For this example, we are robbing from the Example Car 1. Found in Outerra World Sandbox\prg\game\mods\example_models_js\packages\tutorial_car_js . (If you are doing it from Steam, open Steam, go to your library, right-click on Outerra game, select Manage, then Browse local files.

Now open Version 0 - Info. In there, there is a file called car0.js. Copy it and put it to the folder with your own vehicle, next to the .objdef. Open the file car0.js. Ideally, you should open it with a JavaScript code editor, or Notepad++, but you can do it with Notepad too. A vehicle in Outerra needs four things:

  1. Physics set to "vehicle".
  2. init_chassis() function in the script.
  3. init_vehicle() function in the script.
  4. update_frame() function in the script.

We already set the physics to "vehicle" in the first step. The file car0.js contains the other three requirements (as it contains those functions). Once we finish this step, we will find our new vehicle in the vehicle selector inside the game. (But it will not be able to move yet). If you want, you can check it out.

This is what the base script looks like:


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) {}

As you can see, there are only three functions in the code. Two of them do nothing yet. You don't need to do anything with them, but they need to exist. init_chassis has to return something, but for now you can just copy that what is written in the example. You need init_chassis in the first step because it sets the mass of the vehicle. It is defaultly set to 1000kg, but you can set it to your own value.

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 it has got no wheels. In this step we fix that.

Wheels by added 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 parameter 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.