Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Pages: 1 [2] 3 4 5

Author Topic: Importer and vehicle physics video  (Read 64472 times)

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #15 on: November 14, 2012, 12:14:35 pm »

I modified the js a bit to have a more comfortable driving and so far it seems to work good.

this is the new init_chassis:
Code: [Select]
function init_chassis(){
  var wheelparam = {
    radius: 0.30,
    width: 0.20,
    suspension_max: 0.1,
    suspension_min: -0.05,
    suspension_stiffness: 50.0,
    damping_compression: 0.06,
    damping_relaxation: 0.05,
    slip: 2.2,
    roll_influence: 0.1,
    rotation: -1
  };
  this.add_wheel('wheel_FL', wheelparam);
  this.add_wheel('wheel_FR', wheelparam);
  this.add_wheel('wheel_RL', wheelparam);
  this.add_wheel('wheel_RR', wheelparam);
 
  return {mass:1500, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}

I'm also experimenting a bit at adding the engine sound, but getting the pitch right is not so easy.
Also, i'm not aware of any free sound for that. I'm using some from rFactor but obviously those aren't redistributable.
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

Chaoz

  • Full Member
  • ***
  • Posts: 156
  • newbie
Re: Importer and vehicle physics video
« Reply #16 on: November 14, 2012, 01:34:06 pm »

I toyed around with the engine sound to but i couldn't find a sound that sounded good or real when pitched since expacially the sports version of BMW have a very distict sound when accelerating, which difers greatly from the idle sound.... the only thing i could do was a engine start sound...

EDIT: I took mine from
« Last Edit: November 14, 2012, 01:35:59 pm by Chaoz »
Logged

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #17 on: November 15, 2012, 04:49:12 pm »

I implemented a still basic but a bit more realistic engine, with gears too (5 + 1).
The engine curve needs some adjustments though. Too little force when starting.
Code: [Select]
//vehicle script file
//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation

var sound = -1;
var gear = 0;

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
  var wheelparam = {
    radius: 0.30,
    width: 0.20,
    suspension_max: 0.1,
    suspension_min: -0.05,
    suspension_stiffness: 50.0,
    damping_compression: 0.06,
    damping_relaxation: 0.05,
    slip: 2.2,
    roll_influence: 0.1,
    rotation: -1
  };
  this.add_wheel('wheel_FL', wheelparam);
  this.add_wheel('wheel_FR', wheelparam);
  this.add_wheel('wheel_RL', wheelparam);
  this.add_wheel('wheel_RR', wheelparam);
 
  this.load_sound("diesel-engine-start.ogg");
  this.load_sound("18L16V_onidle_ex.ogg");
  this.load_sound("18L16V_onverylow_in.ogg");
  this.add_sound_emitter("wheel_FL");

  return {mass:1500, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}

//invoked for each new instance of the vehicle
function init_vehicle(){
  this.set_fps_camera_pos({x:-0.33,y:-0.25,z:1.15});
 
  this.snd = this.sound();
  this.snd.set_ref_distance(0, 9.0);

  this.started = 0;
}

//invoked when engine starts or stops
function engine(start){
  if(start) {
    this.started = 1;
        this.sound = 0;
    this.snd.play(0, 0, false, false);
  }
}

const BF = 4000.0;

function force(rpm) {
    var maxrpm = 7500;
    var mid = maxrpm / 2.0;

    var x = rpm - (mid - 200);
    return (-x * x + (mid + 200) * (mid + 200)) / 3000;
}

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering) {
  if (this.started != 1)
    return;

  steering *= 0.6;
  this.steer(-2, steering);
 
  var radius = 0.24;
  var wheels = Math.abs(this.speed()) / (radius * (2 * 3.1415));

  var kmh = this.speed()*3.6;
 
  var gears = [ 1.0, 4.20, 2.49, 1.66, 1.24, 1.00 ]; //R, 1, 2, 3, 4, 5
 
  var speed = Math.abs(kmh);
  if (engine < 0)
    this.gear = 0;
  else if (speed < 40)
    this.gear = 1;
  else if (speed < 75)
        this.gear = 2;
  else if (speed < 115)
    this.gear = 3;
  else if (speed < 150)
        this.gear = 4;
  else
    this.gear = 5;

  var ratio = 3.0;
  var rpm = wheels * gears[this.gear] * ratio * 60;
  engine *= force(rpm);
 
  this.wheel_force(2, engine);
  this.wheel_force(3, engine);
 
  brake *= BF;
  this.wheel_brake(-1, brake);

  this.animate_wheels();
 
  if (engine == 0 && ((this.sound == 0 && !this.snd.is_playing(0)) || this.sound == 2)) {
        this.snd.stop(0);
    this.snd.play(0, 1, true, false);
        this.sound = 1;
  } else if (engine != 0 && ((this.sound == 0 && !this.snd.is_playing(0)) || this.sound == 1)) {
        this.snd.stop(0);
    this.snd.play(0, 2, true, false);
        this.sound = 2;
  }
 
  var basepitch = [ 0, 1, 0.7 ];
  if (this.sound > 0) {
    var pitch = rpm / 5000.0;
    this.snd.set_pitch(0, pitch + basepitch[this.sound]);
  }
}

That code also manages the sound. I still couldn't find any good free sample so if you want to try some sound you have you need to put them in the package folder, change the file names at lines 26,27, 28 and adjust the pitch at line 114 if needed. Otherwise comment out the sound parts.

With this driving the BMW starts to be enjoyable :)

EDIT: Silly me, i just realised i put a wrong ratio for the reverse gear. Should be something like 4. (If you have the real value that would be welcome. The other ones are real.)
« Last Edit: November 15, 2012, 04:52:16 pm by giucam »
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

murkz

  • Full Member
  • ***
  • Posts: 152
    • The Antisocial Gamer
Re: Importer and vehicle physics video
« Reply #18 on: November 15, 2012, 04:55:30 pm »

WoW giucam, very nice indeed, is it possible to have multiple revers gears as well. Some tanks and vehicles have 4 or more revers gears.

Jeff

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #19 on: November 15, 2012, 05:03:19 pm »

Yeah, it's sure possible. You just need to add the ratios in the gears array and add some ifs to choose the rigth gear.

btw, Cameni, can we have some speedometer in km/h? I'm using the airplane HUD right now, but i'm not even sure i know how much a knot is...  :P
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Importer and vehicle physics video
« Reply #20 on: November 15, 2012, 05:24:02 pm »

can we have some speedometer in km/h? I'm using the airplane HUD right now, but i'm not even sure i know how much a knot is...  :P

Actually the HUD speedo is Meters per Second. It just says knots...
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Importer and vehicle physics video
« Reply #21 on: November 16, 2012, 10:16:23 am »

btw, Cameni, can we have some speedometer in km/h? I'm using the airplane HUD right now, but i'm not even sure i know how much a knot is...  :P
Yea we need to make it configurable and switch to values used with different vehicles.

Nice work!
Logged

murkz

  • Full Member
  • ***
  • Posts: 152
    • The Antisocial Gamer
Re: Importer and vehicle physics video
« Reply #22 on: November 16, 2012, 10:40:44 am »



A short WIP of the Schwerer Panzerspähwagen 232 used for testing the new Outerra importer and in understanding how the vehicle script works.

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #23 on: November 16, 2012, 11:38:02 am »

Here's version 2.0. (or maybe 0.2) ;)

Code: [Select]
//vehicle script file
//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation

var sound = -1;

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
    var wheelparam = {
        radius: 0.30,
        width: 0.20,
        suspension_max: 0.1,
        suspension_min: -0.05,
        suspension_stiffness: 50.0,
        damping_compression: 0.06,
        damping_relaxation: 0.05,
        slip: 2.2,
        roll_influence: 0.1,
        rotation: -1
    };
    this.add_wheel('wheel_FL', wheelparam);
    this.add_wheel('wheel_FR', wheelparam);
    this.add_wheel('wheel_RL', wheelparam);
    this.add_wheel('wheel_RR', wheelparam);

    this.load_sound("diesel-engine-start.ogg"); //start
    this.load_sound("18L16V_onidle_ex.ogg");    //idle
    this.load_sound("18L16V_onverylow_in.ogg"); //throttle
    this.basepitch = [ 0, 1, 0.7 ];             //base pitch for start, idle, throttle
    this.add_sound_emitter("wheel_FL");

    //engine properties -- modify these to change the engine behaviour
    this.wheelRadius = 0.24;

    this.torquePoints = [ { rpm: 0,    torque: 220},
                          { rpm: 1000, torque: 265},
                          { rpm: 2000, torque: 290},
                          { rpm: 3000, torque: 315},
                          { rpm: 4000, torque: 335},
                          { rpm: 4900, torque: 365},
                          { rpm: 6000, torque: 340},
                          { rpm: 7000, torque: 320},
                          { rpm: 8000, torque: 290},
                          { rpm: 8100, torque: 0  } ];

    this.forwardGears = [ { ratio: 4.20, shiftUp: 7000, shiftDown: -1   },
                          { ratio: 2.49, shiftUp: 7000, shiftDown: 4000 },
                          { ratio: 1.66, shiftUp: 7000, shiftDown: 4000 },
                          { ratio: 1.24, shiftUp: 7000, shiftDown: 4000 },
                          { ratio: 1.00, shiftUp: -1,   shiftDown: 4000 } ];
    this.reverseGears = [ { ratio: 4.20, shiftUp: -1, shiftDown: -1 } ];

    this.finalRatio = 3;
    this.torqueMultiplier = 10;
    //end of engine properties

    this.torque = engineTorque;

    return {mass:1500, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}

//invoked for each new instance of the vehicle
function init_vehicle() {
    this.set_fps_camera_pos({x:-0.33,y:-0.25,z:1.15});

    this.snd = this.sound();
    this.snd.set_ref_distance(0, 9.0);

    this.started = 0;
    this.gear = 0;
}

//invoked when engine starts or stops
function engine(start) {
    if (start) {
        this.started = 1;
        this.sound = 0;
        this.snd.play(0, 0, false, false);
    }
}

const BF = 4000.0;

function engineTorque(rpm) {
    var min = 0;
    var max = this.torquePoints.length - 1;

    if (rpm > this.torquePoints[max].rpm || rpm < this.torquePoints[min].rpm)
        return 0;

    while (max - min > 1) {
        var mid = Math.floor(min + (max - min) / 2);
        var tp = this.torquePoints[mid];
        if (tp.rpm == rpm) {
            return tp.torque;
        } else if (tp.rpm > rpm) {
            max = mid;
        } else {
            min = mid;
        }
    }

    var minTp = this.torquePoints[min];
    var maxTp = this.torquePoints[max];
    var TM = maxTp.torque;
    var Tm = minTp.torque;
    var RM = maxTp.rpm;
    var Rm = minTp.rpm;

    var a = (TM - Tm) / (RM - Rm);

    return rpm * a + Tm - Rm * a;
}

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering) {
    if (this.started != 1)
        return;

    steering *= 0.6;
    this.steer(-2, steering);


    var khm = Math.abs(this.speed()) * 3.6;
    var wheels = Math.abs(this.speed()) / (this.wheelRadius * (2 * Math.PI));

    var gears;
    if (this.speed() >= 0) {
        gears = this.forwardGears;
    } else {
        gears = this.reverseGears;
    }

    var rpm = wheels * gears[this.gear].ratio * this.finalRatio * 60;

    //automatic gear shifting
    var currentGear = gears[this.gear];
    if (rpm > currentGear.shiftUp && this.gear < gears.length - 1) {
        this.gear += 1;
    } else if (rpm < currentGear.shiftDown && this.gear > 0) {
        this.gear -= 1;
    }

    var force = engine * this.torque(rpm) * this.torqueMultiplier;
    this.wheel_force(2, force);
    this.wheel_force(3, force);


    brake *= BF;
    this.wheel_brake(-1, brake);

    this.animate_wheels();

    if (engine == 0 && ((this.sound == 0 && !this.snd.is_playing(0)) || this.sound == 2)) { //idle
        this.snd.stop(0);
        this.snd.play(0, 1, true, false);
        this.sound = 1;
    } else if (engine != 0 && ((this.sound == 0 && !this.snd.is_playing(0)) || this.sound == 1)) { //throttle
        this.snd.stop(0);
        this.snd.play(0, 2, true, false);
        this.sound = 2;
    }

    if (this.sound > 0) {
        var pitch = rpm / 5000.0;
        this.snd.set_pitch(0, pitch + this.basepitch[this.sound]);
    }
}

It doesn't use anymore a parabolic function for the engine torque but it interpolates from some given points in the torque by rpm graph. I took those from a graph of a M3 i found on internet but given there are many M3s i don't know if they are the true ones. It does 0-100 km/h in ~ 9 secs, maybe it's underpowered.
It also supports multiple reverse gears and a more flexible way for it to shift gear.

All the values it uses are defined in the init_chassis(), if you want to adapt it to another vehicle.
« Last Edit: November 16, 2012, 11:42:22 am by giucam »
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Importer and vehicle physics video
« Reply #24 on: November 16, 2012, 09:54:07 pm »

You are doing God's work my child.. But seriously. 9 Seconds to 60mph is an eternity. Is there a lot of wheel spin?
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

murkz

  • Full Member
  • ***
  • Posts: 152
    • The Antisocial Gamer
Re: Importer and vehicle physics video
« Reply #25 on: November 17, 2012, 04:50:40 am »

Outerra - Kübelwagen in PanzerTerra with sounds.



Here is another little update, this time with sounds and a new model. The modified script for the Kübelwagen needs some work, though as a start I am happy with it.

Kübelwagen is supplied by Foo'Bar
http://foorum.mexxoft.com/index.php?sid=4837f3d92f4fa277b8c6a22c9ef379a3

Kübelwagen sounds have been supplied by Olaf NSU Binder

The Kübelwagen is using a modified version of giucam's vehicle script.
http://www.outerra.com/forum/index.php?topic=1326.msg15518#msg15518

Thank you to all.

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #26 on: November 17, 2012, 05:00:35 am »

Quote
You are doing God's work my child.. But seriously. 9 Seconds to 60mph is an eternity. Is there a lot of wheel spin?

mmh... i didn't check that but anyway i get 9 secs with a little test app i made to develop the engine model and which has a dumb physics and no wheel spinning.
However, increasing the engine torque is just a matter of increasing the value of this.torqueMultiplier. With 15 it takes ~6 secs and with 20 ~4.50 secs.
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

murkz

  • Full Member
  • ***
  • Posts: 152
    • The Antisocial Gamer
Re: Importer and vehicle physics video
« Reply #27 on: November 17, 2012, 06:20:55 am »

Hi Giucam,

Is there a way with the new settings to limit the top speed, I would like to limit the kubel's top speed.

giucam

  • Full Member
  • ***
  • Posts: 171
  • It's an ugly pile of bones... like me.
Re: Importer and vehicle physics video
« Reply #28 on: November 17, 2012, 06:37:29 am »

No, there's no way currently to force a maximum speed, even though adding support is easy.
Anyway you can change the torque curve so that at the rpm of the maximum speed the torque is 0.
Logged
ResidualVM 0.1.1 is OUT! www.residualvm.org

ddenn

  • Sr. Member
  • ****
  • Posts: 374
Re: Importer and vehicle physics video
« Reply #29 on: November 17, 2012, 02:40:48 pm »

Nice work Giucam!

Cameni, does bullet physics have center of gravity point? BMW behaves now exactly like my mercedes on JSBSim and CG at zero height. If I move CG up, the car starts behave right, leaning forward when brake, and backwards with acceleration. Is there way to control CG on vehicles with Bullet physics?

Also can we have some custom commands to control animations, like door/hood/windows opening etc?
« Last Edit: November 17, 2012, 02:42:34 pm by ddenn »
Logged
i7 3930K 3.50 (3.80) Ghz, 32Gb RAM, GTX980 4 Gb VRAM, Windows 7 64-bit

About Outerra in Russian
Pages: 1 [2] 3 4 5