Tweaky Tweaky..
//invoked only the first time the model is loaded, or upon reload
function init_chassis()
{
var wheelparam = {
radius: 0.6,
width: 0.265,
suspension_max: 1.0,
suspension_min: -0.20,
suspension_stiffness: 14.0,
damping_compression: 0.05,
damping_relaxation: 0.2,
slip: 0.70,
roll_influnce: 0.1,
rotation: -1,
}
this.add_wheel('wheel_0', wheelparam);
this.add_wheel('wheel_1', wheelparam);
this.add_wheel('wheel_2', wheelparam);
this.add_wheel('wheel_3', wheelparam);
this.add_wheel('wheel_4', wheelparam);
this.add_wheel('wheel_5', wheelparam);
this.add_wheel('wheel_6', wheelparam);
this.add_wheel('wheel_7', wheelparam);
//sounds
this.load_sound("diesel-engine-start.ogg");
this.load_sound("diesel-engine-idle.ogg");
this.add_sound_emitter("wheel_0");
return {mass:7315, steering:2.0, steering_ecf:20, centering:2.0, centering_ecf: 20,
com:{z:0.8, y:-0.6, x:2 }};
}
//invoked for each new instance of the vehicle
function init_vehicle()
{
this.set_fps_camera_pos({x:1.7,y:-1.0,z:3.6});
this.snd = this.sound();
this.snd.set_ref_distance(0, 9.0);
this.started = 0;
}
function engine(start)
{
if(start) {
this.started=1;
this.snd.play(0, 0, false, false);
}
}
const EF = 12000.0;
const BF = 4000.0;
const maxkmh = 40;
const forceloss = EF / (0.4*maxkmh + 2);
//invoked each frame to handle inputs and animate the model
function update_frame(dt, engine, brake, steering)
{
var kmh = this.speed()*3.6;
//reduce engine force with speed (hack)
var redux = engine>=0 ? 0.2 : 0.6;
var esign = engine<0 ? -1 : 1;
engine = EF*Math.abs(engine);
var force = (esign>0) == (kmh>=0)
? engine/(redux*Math.abs(kmh) + 1)
: engine;
force -= forceloss;
force = Math.max(0.0, Math.min(force, engine));
engine = esign*force;
steering *= 0.40;
this.steer(0, steering);
this.steer(1, steering);
this.steer(2, steering);
this.steer(3, steering);
this.steer(4, -steering);
this.steer(5, -steering);
this.steer(6, -steering);
this.steer(7, -steering);
if(this.started>1)
this.wheel_force(0, engine);
this.wheel_force(1, engine);
this.wheel_force(2, engine);
this.wheel_force(3, engine);
this.wheel_force(4, engine);
this.wheel_force(5, engine);
this.wheel_force(6, engine);
this.wheel_force(7, engine);
brake *= BF;
this.wheel_brake(-1, brake);
if(this.started==1 && !this.snd.is_playing(0)) {
this.started=2;
this.snd.play(0, 1, true, false);
}
else if(this.started==2) {
var pitch = Math.abs(kmh)/20.0;
var g = kmh>0 ? Math.floor(pitch) : 0;
var f = pitch - g;
f += 0.5*g;
this.snd.set_pitch(0, 0.5*f + 1.0);
}
this.animate_wheels();
}
Give that a whirl. I also attached it.