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.

Author Topic: Problem with modding vehicle  (Read 13022 times)

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Problem with modding vehicle
« on: August 02, 2016, 02:24:02 pm »

Hello! My problem is... well... annoying. I "borrowed" car model from warehouse in Google Sketchup. I Put it into Outerra, "borrowed" script from theshanergy and modified it to work for my car. Reloaded and... Car is hovering! I also cant drive it. Even animations dont work. Also the second problem is that wheels from right side dont have a texture, when those on opposite side have. This same problem appears on door, but this time door on left side are without texture.
Here is script:
Code: [Select]
//vehicle script file

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
 
  var wheelparam = {
    radius: 0.32,
    width: 0.90,
    suspension_max: .035,
    suspension_min: -0.1,
    suspension_stiffness: 30,
    damping_compression: 0.3,
    damping_relaxation: 0.2,
    slip: 2,
    slip_lateral_coef: .85,
    roll_influence: .05,
    rotation: -1
  };


  this.add_wheel('Wheel_1', wheelparam);
  this.add_wheel('Wheel_2', wheelparam);
  this.add_wheel('Wheel_3', wheelparam);
  this.add_wheel('Wheel_4', wheelparam);

  // load sounds
  this.load_sound("sounds/start.ogg"); // startup
  this.load_sound("sounds/decel.ogg"); // engine decel
  this.load_sound("sounds/accel.ogg"); // engine accel
  this.load_sound("sounds/shutdown.ogg"); // shutdown
  this.add_sound_emitter("exhaust");
 

  // engine & transmission properties
  this.wheelRadius = 0.342;

  this.torquePoints = [ { rpm: 0,  torque: 100},
                           { rpm: 1000, torque: 120},
                           { rpm: 2000, torque: 130},
                           { rpm: 3000, torque: 145},
                           { rpm: 4000, torque: 195},
                           { rpm: 5000, torque: 370},
                           { rpm: 6000, torque: 550},
                           { rpm: 7000, torque: 530},
                           { rpm: 8000, torque: 500},
                           { rpm: 9000, torque: 0} ];
  this.forwardGears = [ { ratio: 3.827, shiftUp: 7500, shiftDown: -1   },
                        { ratio: 2.360, shiftUp: 7500, shiftDown: 3400 },
                        { ratio: 1.685, shiftUp: 7500, shiftDown: 3600 },
                        { ratio: 1.312, shiftUp: 7500, shiftDown: 4000 },
                        { ratio: 0.930, shiftUp: 7500, shiftDown: 4000 },
                        { ratio: 1.000, shiftUp: 7500, shiftDown: 4000 },
                        { ratio: 0.793, shiftUp: -1,   shiftDown: 4000 } ];
  this.reverseGears = [ { ratio: 3.280, shiftUp: -1, shiftDown: -1 } ];

  this.finalRatio = 4.2;
  this.torqueMultiplier = 10;
  this.maximumSpeed = 300; // speed in kmh. a value < 0 means there's no maximum speed
  this.engineBrakeCoefficient = .5; // engine brake
  this.breakingForce = 5500.0;


  this.maxPowerTP = this.torquePoints[0];
  this.maxRPM = 0;
  var maxPw = 0;
  for (var i = 1; i < this.torquePoints.length; ++i) {
      var tp = this.torquePoints[i];
      if (tp.rpm * tp.torque > maxPw) {
          this.maxPowerTP = tp;
      }
      if (tp.rpm > this.maxRPM) {
          this.maxRPM = tp.rpm;
      }
  }

  this.neutroGear = { ratio: 0.0, shiftUp: -1, shiftDown: -1, index: 0 };
  var prev = null;
  for (var i = 0; i < this.forwardGears.length; ++i) {
      var gear = this.forwardGears[i];
      if (prev)
          prev.next = gear;
      gear.prev = prev;
      gear.index = i + 1;
      prev = gear;
  }

  prev = null;
  for (var i = 0; i < this.reverseGears.length; ++i) {
      var gear = this.reverseGears[i];
      if (prev)
          prev.next = gear;
      gear.prev = prev;
      gear.index = -i - 1;
      prev = gear;
  }


  this.torque = engineTorque;
 
  // return chassis parameters
  return {mass:1420, steering:3, steering_ecf:90, centering: 1.6, centering_ecf:20, com:{ z:0.2 }};
}

//invoked for each new instance of the vehicle
function init_vehicle(){
 
  // interior camera placement
  this.set_fps_camera_pos({x:-0.36,y:-0.3,z:1.05});
 
  // geom
  this.geom = this.get_geomob(0);
 
  // steering wheel
  this.swheel = this.geom.get_joint("steering_wheel");
 
  // brakes
  this.brake_FL = this.geom.get_joint('brake_FL');
  this.brake_FR = this.geom.get_joint('brake_FR');
  this.brake_RL = this.geom.get_joint('brake_RL');
  this.brake_RR = this.geom.get_joint('brake_RR');
 
  // gauges
  this.speedo = this.geom.get_joint("speedo");
  this.tach = this.geom.get_joint("tach");
 
  // hood, doors, hatch
  this.hood = this.geom.get_joint("hood");
  this.hood_open = false;
 
  this.hatch = this.geom.get_joint("hatch");
  this.hatch_open = false;
 
  this.door_L = this.geom.get_joint("door_L");
  this.door_L_open = false;
 
  this.door_R = this.geom.get_joint("door_R");
  this.door_R_open = false;
 
  // sound
  this.snd = this.sound();
  this.snd.set_ref_distance(0, 5);
 
  // exhaust sound
  this.exhaust = this.geom.get_joint('exhaust');
  this.exhaust_src = this.snd.create_source(this.exhaust);
  this.snd.set_ref_distance(this.exhaust_src, 5);
 
  // turbo sound
  this.turbo_snd = this.snd.load_sound("sounds/turbo.ogg");
  this.turbo_src = this.snd.create_source(this.exhaust);
  this.snd.set_ref_distance(this.turbo_src, 6);
 
  // bov sound
  this.bov_snd = this.snd.load_sound("sounds/bov.ogg");
  this.bov_src = this.snd.create_source(this.exhaust);
  this.snd.set_ref_distance(this.bov_src, 5);
 
  // door sounds
  this.door_open_snd = this.snd.load_sound("sounds/door_open.ogg");
  this.door_close_snd = this.snd.load_sound("sounds/door_close.ogg");
  this.door_L_src = this.snd.create_source(this.door_L);
  this.snd.set_ref_distance(this.door_L_src, 5);
  this.door_R_src = this.snd.create_source(this.door_R);
  this.snd.set_ref_distance(this.door_R_src, 5);
 

  this.started = false;
  this.gear = this.neutroGear;
  this.direction = 0;
 
}

// engine start
function engine(start){
  if (start) {
      this.started = true;
      this.sound = 0;
      this.snd.play(0, 0, false, false);
      this.snd.set_pitch(0, 1);
  }
  else {
    this.started = false;
    this.sound = 4;
    this.snd.play_sound(0, 3);
    this.snd.set_pitch(0, 1);
  }
}

// action keys
function action(key, value, dt){

  // gearing
  if (value == 1) {
    switch(key) {
      case AFire:
        this.boost = true;
        this.log_inf('boosting');
        break;
      case AAuxb1:
        this.hood_open = !this.hood_open;
        break;
      case AAuxb2:
        this.hatch_open = !this.hatch_open;
        break;
      case AAuxb3:
        // open
        if(!this.door_L_open) {
          this.snd.play_sound(this.door_L_src, this.door_open_snd);
          this.door_L_open = true;
        }
        // close
        else {
          this.snd.play_sound(this.door_L_src, this.door_close_snd);
          this.door_L_open = false;
        }
        break;
      case AAuxb4:
        // open
        if(!this.door_R_open) {
          this.snd.play_sound(this.door_R_src, this.door_open_snd);
          this.door_R_open = true;
        }
        // close
        else {
          this.snd.play_sound(this.door_R_src, this.door_close_snd);
          this.door_R_open = false;
        }
        break;
    }
  }
  else {
    switch(key) {
      case AFire:
        this.boost = false;
        break;
    }
  }

   
}

var hood_angle = 0;
var hatch_angle = 0;
var door_L_angle = 0;
var door_R_angle = 0;

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

  // engine is starting
  if(this.sound == 0 && this.snd.is_playing(0)) {
    return;
  }
   
  // steering
  steering *= 0.6;
  this.steer(-2, steering);

  // steering wheel
  var steerAngle = steering *= 6;
  this.geom.rotate_joint_orig(this.swheel, steerAngle, {x:0,y:-1,z:0});
 
  // brake movement
  var Wheel_1 =  this.wheel(0);
  var Wheel_2 =  this.wheel(1);
  var Wheel_3 =  this.wheel(2);
  var Wheel_4 =  this.wheel(3);

  var brake_height_adjust = 0.04;
  var Wheel_1_height = Wheel_1.caxle - brake_height_adjust;
  var Wheel_2_height = Wheel_2.caxle - brake_height_adjust;
  var Wheel_3_height = Wheel_3.caxle - brake_height_adjust;
  var Wheel_4_height = Wheel_4.caxle - brake_height_adjust;
 
  this.geom.move_joint_orig(this.brake_FL, {z:-Wheel_1_height});
  this.geom.move_joint_orig(this.brake_FR, {z:-Wheel_2_height});
  this.geom.move_joint_orig(this.brake_RL, {z:-Wheel_3_height});
  this.geom.move_joint_orig(this.brake_RR, {z:-Wheel_4_height});
 
  var brake_rot = steering * 0.2;
 
  this.geom.rotate_joint(this.brake_FL, brake_rot, {x:0,y:0,z:1});
  this.geom.rotate_joint(this.brake_FR, brake_rot, {x:0,y:0,z:1});
 
  // hood
  var max_hood_angle = 0.8;
  if(this.hood_open == true) {
    hood_angle+=dt;
  }
  else {
    hood_angle-=dt;
  }
  if(hood_angle<=0)hood_angle=0;
  if(hood_angle>=max_hood_angle)hood_angle=max_hood_angle;
 
  this.geom.rotate_joint_orig(this.hood, hood_angle, {x:-1,y:0,z:0});
 
  // hatch
  var max_hatch_angle = 0.8;
  if(this.hatch_open == true) {
    hatch_angle+=dt;
  }
  else {
    hatch_angle-=dt;
  }
  if(hatch_angle<=0)hatch_angle=0;
  if(hatch_angle>=max_hatch_angle)hatch_angle=max_hatch_angle;
 
  this.geom.rotate_joint_orig(this.hatch, hatch_angle, {x:1,y:0,z:0});
 
  // doors
  var max_door_angle = 0.8;
  if(this.door_L_open == true) {
    door_L_angle+=dt;
  }
  else {
    door_L_angle-=dt;
  }
  if(door_L_angle<=0)door_L_angle=0;
  if(door_L_angle>=max_door_angle)door_L_angle=max_door_angle;
 
  if(this.door_R_open == true) {
    door_R_angle+=dt;
  }
  else {
    door_R_angle-=dt;
  }
  if(door_R_angle<=0)door_R_angle=0;
  if(door_R_angle>=max_door_angle)door_R_angle=max_door_angle;
 
  this.geom.rotate_joint_orig(this.door_L, door_L_angle, {x:0,y:0,z:-1});
  this.geom.rotate_joint_orig(this.door_R, door_R_angle, {x:0,y:0,z:1});
 

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

  //automatic gear shifting
  var rpm = wheels * this.gear.ratio * this.finalRatio * 60;
  if (rpm < 10 && this.gear.index != 0) {
    this.gear = this.neutroGear;
    this.direction = 0;
    // this.log_inf("neutro");
  }
  if (engine != 0.0 && sign(engine) != this.direction) {
    this.direction = sign(engine);
    if (this.direction == 1.0) {
      this.gear = this.forwardGears[0];
      // this.log_inf("forward, gear " + this.gear.index);
    } else if (this.direction == -1.0) {
      this.gear = this.reverseGears[0];
      // this.log_inf("reverse, gear " + this.gear.index);
    }
  }

  if (rpm > this.gear.shiftUp && this.gear.next) {
    this.gear = this.gear.next;
   
    // bov sound
    this.snd.play(this.bov_src, this.bov_snd, false, false);
   
    // this.log_inf("gear up " + this.gear.index);
  } else if (rpm < this.gear.shiftDown && this.gear.prev) {
    this.gear = this.gear.prev;
    // this.log_inf("gear down " + this.gear.index);
  }

  // power to wheels
  if(this.maximumSpeed < 0 || kmh < this.maximumSpeed) {
    force = engine * this.torque(rpm) * this.torqueMultiplier * this.gear.ratio;
  } else {
    force = 0;
  }
  this.wheel_force(0, force);
  this.wheel_force(1, force);

  // brakes
  var static_friction = 0.1;
  var engineBrake = this.maxPowerTP.torque * this.engineBrakeCoefficient * this.gear.ratio * (static_friction + (1.0 - static_friction) * rpm / this.maxRPM);
  brake *= this.breakingForce;
  this.wheel_brake(-1, brake + engineBrake);
 
 
  // engine sounds
  if (this.gear.index == 0 && (!this.snd.is_playing(0) || this.sound != 1)) { // idle
    this.snd.stop(0);
    this.snd.play(0, 1, true, false);
    this.sound = 1;
  } else if (this.gear.index != 0 && engine == 0 && (!this.snd.is_playing(0) || this.sound != 2)) { // decel
    this.snd.stop(0);
    this.snd.stop(this.turbo_src);
    this.snd.play(0, 1, true, false);
    this.sound = 2;
  } else if (this.gear.index != 0 && engine != 0 && (!this.snd.is_playing(0) || this.sound != 3)) { // throttle
    this.snd.stop(0);
    this.snd.play(0, 2, true, false);
    this.sound = 3;
   
    // turbo spool
    this.snd.play(this.turbo_src, this.turbo_snd, true, false);
   
  }
 
  // engine pitch
  var engine_pitch = (1.2 * rpm / this.maxRPM) + .22;
  if(this.sound == 2 || this.sound == 3) { // accel decel
    this.snd.set_pitch(0, engine_pitch);
  } else if (this.sound == 1) { // idle
    this.snd.set_pitch(0, .2);
  } else { // start stop
    this.snd.set_pitch(0, 1);
  }
 
  // adjust turbo spool pitch and gain
  if(this.snd.is_playing(this.turbo_src)) {
    var turbo_gain = clamp((rpm - 5000) / 1000, 0, 5);
    this.snd.set_gain(this.turbo_src, turbo_gain);
    this.snd.set_pitch(this.turbo_src, engine_pitch * 1.2);
  }
 
 
  // gauges
  var speedo = kmh / 48;
  if (speedo < 180) {
    this.geom.rotate_joint_orig(this.speedo, speedo, {x:0,y:0,z:-1});
  }
  var tach = rpm / 2050;
  if (tach < 180) {
    this.geom.rotate_joint_orig(this.tach, tach, {x:0,y:0,z:-1});
  }
 
 
  // doughnuts/boost
  if(this.boost === true) {
    var boost = steering * 400;
    this.extra_force({x:0,y:-10,z:0},{x:boost});
  }
 
  // downforce
  var downforce = absSpeed * 12;
  this.extra_force({x:0,y:0,z:0},{z:-downforce});
 
  // spin tires
  this.animate_wheels();
}



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;
}

function sign(x) {
    return (x > 0.0 ? 1 : (x < 0.0 ? -1 : 0));
}

function clamp(val, min, max){
  if(val < min) return min; else if(val > max) return max; else return val;
}


IMAGE: https://www.imghost.eu/image/c9u
Logged

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: Problem with modding vehicle
« Reply #1 on: August 02, 2016, 04:24:48 pm »

Hi!

So you certainly have a script error which will break the physics. This is most likely caused either by the use of a method or function parameter that no longer exists, or a syntax error.

Press Alt + L keys to bring up the console, you should see something about an error in red text and it will indicate the line of the first error in brackets, like (231) and possibly what type of error it is, such has Object has no object, or expect identifier, or some such error.

Looking briefly at the code I assume some of the joints from theshanergy's vehicle were called in get_joint that do not exist in your model, and it looks like some of the methods in the function update_frame are expecting variables from the function action which is no longer supported since the extended controls were implemented.

I might suggest you begin with an up-to-date script, such as t817.js found in Anteworld/packages/outerra/t817.js and reduce it to only the necessary code that applies directly to your vehicle. I will also use a JS debugger to identify syntax errors, online ones exist such as jsbin.com

In terms of textures, check your .mtl file and make sure there are corresponding texture files for the material albedos, as they may not have been imported automatically or exported when you saved the FBX file. There is plenty of information about that elsewhere on the forum.

Regards,
Uriah
« Last Edit: August 02, 2016, 04:28:41 pm by Uriah »
Logged

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Re: Problem with modding vehicle
« Reply #2 on: August 03, 2016, 05:38:12 am »

Hi!

I checked the t817 script. Remade it a bit and now... well just say... only one wheel can rotate and it doesnt rotate as it should. It should be normal, but it can just rotate 360 degree and not even at center.

About textures, i exported it as Collada File, because i have free sketchup.

Code: [Select]
var debug = false;

var log = function (msg) {
    if (!debug) return;
    this.log('ot-debug ' + msg);
};

var axle2coef=1.0,hidech=false, swheel;
var lcabin,brakemask,revmask,turnlmask,turnrmask;

var DefaultWheelParams = {
    radius: { default: 0.7 },
    width: { default: 0.45 },
    differential: { default: true },

    suspension_max: { default: 0.2, min:-2, max:2, step: 0.01 },
    suspension_min: { default: -0.35, min:-2, max:2, step: 0.01 },
    suspension_stiffness: { default: 5.0, min:0, max:10, step: 0.1 },
    damping_compression: { default: 0.2, min:0, max:1, step: 0.01 },
    damping_relaxation: { default: 0.12, min:0, max:1, step: 0.01 },
    grip: { default: 0, min:-1, max:1, step: 0.1 },
    slip_lateral_coef: { default: 3, min: 0, max: 10, step: 0.1 }
};

//invoked only the first time the model is loaded, or upon reload
function init_chassis(param)
{
    log = log.bind(this);
    log('t817.js loaded');

  var par = eval(param);
  hidech = par.type==1;

  var wheelparam = {
    radius: DefaultWheelParams.radius.default,
    width: DefaultWheelParams.width.default,
    differential: DefaultWheelParams.differential.default,

    suspension_max: DefaultWheelParams.suspension_max.default,
    suspension_min: DefaultWheelParams.suspension_min.default,
    suspension_stiffness: DefaultWheelParams.suspension_stiffness.default,
    damping_compression: DefaultWheelParams.damping_compression.default,
    damping_relaxation: DefaultWheelParams.damping_relaxation.default,
    grip: DefaultWheelParams.grip.default,
    slip_lateral_coef: DefaultWheelParams.slip_lateral_coef.default
  };

 
 
  //inputs
  this.register_event("car/engine/reverse",
      function(v) {
        if((v&0x0300) != 0) {
          //shift - toggle differential lock
          var dl = this.differential_lock(0xf, true);
          this.fade(dl ? "diff.lock onads" : "diff.lock off");
        }
        else {
          this.engdir = this.engdir>=0 ? -1 : 1;
          this.light_mask(revmask, this.engdir<0);
          this.fade(this.engdir>0 ? "forward" : "reverse");
        }
      });
  this.register_switch("car/lights/passing", function(v) {
    if(v>0) this.autolights = false;
    this.light_mask(0xf, v>0);
  });
  this.register_switch("car/lights/cabin", function(v) { this.light(lcabin, v>0); });

  //turn signals can have -1/0/1 values
  this.register_switch("car/lights/turn", function(v) {
    if(v==0)
      this.lturn=this.rturn=0;
    else if(v<0)
      {this.lturn ^= 1; this.rturn = 0;}
    else
      {this.rturn ^= 1; this.lturn = 0;}
  });
 
  this.register_event("car/lights/emergency", function(v) { this.emer ^= 1; });

  this.register_event("car/weapons/fire", function() {
    this.fire({x:1,y:4,z:2.8}, {y:1,z:0.1}, 80, 0.2, {x:1,y:.8});
  });
 
  //sounds
  this.load_sound("diesel-engine-start.ogg");
  this.load_sound("diesel-engine-idle.ogg");
  this.load_sound("diesel-engine-stop.ogg");
 
 
  //lights
  var fp = {size:0.1, angle:54, edge:0.08, fadeout:0.2, range:50};
  this.add_spot_light({x:-0.93,y:4.58,z:1.38}, {y:1}, fp);
  this.add_spot_light({x:0.93,y:4.58,z:1.38}, {y:1}, fp);

  //tail lights
  fp = {size:0.12, angle:54, edge:0.8, intensity:0.1, range:5, color:{x:1,y:1e-4}, fadeout:0.2};
  this.add_spot_light({x:-0.90,y:-4.26,z:1.06}, {y:-1}, fp);
  this.add_spot_light({x:0.90,y:-4.26,z:1.06}, {y:-1}, fp);
 
  //brakes
  fp = {size:0.12, angle:54, edge:0.8, intensity:0.1, range:5, color:{x:1,y:1e-3}, fadeout:0};
  var brake =
  this.add_spot_light({x:-0.66,y:-4.26,z:1.06}, {y:-1}, fp);
  this.add_spot_light({x:0.66,y:-4.26,z:1.06}, {y:-1}, fp);
  fp.size = 0.05;
  this.add_spot_light({x:-1.12,y:-4.29,z:0.98}, {y:-1}, fp);
  this.add_spot_light({x:1.12,y:-4.29,z:0.98}, {y:-1}, fp);
  brakemask = 0xf<<brake;

  //reverse
  fp = {size:0.12, angle:84, edge:0.8, intensity:0.2, range:5, fadeout:0};
  var rev =
  this.add_spot_light({x:-0.74,y:-4.26,z:1.06}, {y:-1}, fp);
  this.add_spot_light({x:0.74,y:-4.26,z:1.06}, {y:-1}, fp);
  revmask = 3<<rev;
 
  //turn signals
  fp = {size:0.12, angle:54, edge:0.8, intensity:0.02, color:{x:1,y:0.8}, fadeout:0};
  var turn =
  this.add_spot_light({x:-0.98,y:-4.26,z:1.06}, {y:-1}, fp);
  this.add_spot_light({x:0.98,y:-4.26,z:1.06}, {y:-1}, fp);
 
  fp.size = 0.05; fp.color.y = 0.6; fp.fadeout = 0.02;
  this.add_spot_light({x:-1.12,y:-4.28,z:1.03}, {y:-1}, fp);
  this.add_spot_light({x:1.12,y:-4.28,z:1.03}, {y:-1}, fp);
 
  fp.size = 0.12; fp.intensity = 0.02; fp.color.y = 0.3;
  this.add_spot_light({x:-0.69,y:4.55,z:1.39}, {y:1}, fp);
  this.add_spot_light({x:0.69,y:4.55,z:1.39}, {y:1}, fp);
 
  fp.size = 0.08; fp.angle = 94; fp.intensity = 0.02;
  this.add_spot_light({x:-1.23,y:4.3,z:1.74}, {x:-1}, fp);
  this.add_spot_light({x:1.23,y:4.3,z:1.74}, {x:1}, fp);
  turnlmask = 0x55<<turn;
  turnrmask = 0xaa<<turn;

  //cabin light
  fp = {size:0.05, angle:150, edge:1, range:3, intensity:2, color:{x:1,y:0.8,z:0.7}, fadeout:0.4};
  lcabin = this.add_spot_light({x:0,y:3.9,z:2.62}, {z:-1}, fp);
 
  var mass = hidech ? 12000 : 14000;
  var com = hidech ? 0.4 : 0.8;
 
  //return {mass:mass, com:{z:com}, config: "config/vehicle_config.html?width=0&height=0"};
  return {mass:mass, com:{z:com},
    clearance: 1.5,
    config: "config/vehicle_config.html"};
}

//invoked for each new instance of the vehicle
function init_vehicle()
{
  this.geom = this.get_geomob(0);
  if(hidech)
    this.geom.set_mesh_visible('bed',false);

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

  this.started = 0;
  this.engdir = 1;
  this.time = 0;
  this.lturn = this.rturn = this.emer = 0;
 
  this.autolights = true;
 
  /*{
this.rocket = this.geom.attach_geom(
"GNU/f_10kg_ap_bomb/f_10kg_ap_bomb",
null,//"Rudder",
{x:3.5,y:0,z:0.35},
{x:0,y:0,z:0,w:1});
  }*/
}

function engine(start)
{
  if(start) {
    this.started=1;
    this.snd.play_sound(0, 0);
   
  }
  else {
    this.started=0;
    this.snd.play_sound(0, 2);
  }
}

//handle seat switching
//@return false if given seat/camera doesn't exist
function switch_seat(cam)
{
  if(cam===0)       //driver
    this.set_fps_camera_pos({x:-0.8,y:3.4,z:2.3});
  else if(cam===1)  //right seat
    this.set_fps_camera_pos({x:+0.8,y:3.4,z:2.3});
  else if(cam===2)  //wheel
    this.set_fps_camera_pos({x:-1.8,y:2.0,z:0.6});
  else
    return false;
  return true;
}

var EF = 27000.0;
var BF = 28000.0;
var maxkmh = 100;
var forceloss = EF / (0.2*maxkmh + 1);


//invoked each frame to handle inputs and animate the model
function update_frame(dt, engine, brake, steering, parking)
{
  var kmh = this.speed()*3.6;
 
 
 
  this.time += dt;
  var blt = this.time*0.85;
  var blink = (blt - Math.floor(blt)) > 0.47 ? 1 : 0;
   
  this.light_mask(brakemask, brake>0);
  this.light_mask(turnlmask, blink&(this.lturn|this.emer));
  this.light_mask(turnrmask, blink&(this.rturn|this.emer));
 
  //reduce engine force with speed (hack)
  var redux = this.engdir>=0 ? 0.2 : 0.6;
  engine = EF*Math.abs(engine);
  var force = (this.engdir>=0) == (kmh>=0)
        ? engine/(redux*Math.abs(kmh) + 1)
        : engine;
  force -= forceloss;
  force = Math.max(0.0, Math.min(force, engine));

  engine = force * this.engdir;

 
  this.geom.rotate_joint_orig(swheel, 8*steering, {z:1});
 
  if(this.started>0) {
    this.wheel_force(-1, engine);
    //this.wheel_force(6, engine);
    //this.wheel_force(7, engine);
   
    if(this.autolights) {
      var s = this.solar_time();
      this.light_mask(0xf, s.sun_coef < 0);
    }
  }
   
  brake += parking;
  brake *= BF;
  //brake += 500;  //rolling friction
  this.wheel_brake(-1, brake);
 
  this.animate_wheels();

  if(this.started>0) {
    var rpm = this.max_rpm();
    var pitch = Math.abs(kmh/40) + Math.abs(rpm/200.0);
    var g = rpm>0 ? Math.floor(pitch) : 0;
    var f = pitch - g;
    f += 0.5*g;
    this.snd.set_pitch(0, 0.5*f + 1.0);
  }
}

I would also like to add that i am not programming master. I got only experience from Minecraft Modding and game making in Unity, so please dont be mad :)

Image of wheel error: https://drive.google.com/file/d/0B2qf59_YbNcCMmluMFh3Q3JmbW8/view?usp=sharing
« Last Edit: August 03, 2016, 08:48:09 am by OskiekSL »
Logged

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Re: Problem with modding vehicle
« Reply #3 on: August 05, 2016, 02:02:50 pm »

DID THIS!!! CAR FINALLY IS DRIVEABLE, But...

It's like center of mass is badly placed, so car flips on roof and fall underground.

Now wheels are spinning like not on center, but on edge
Last thing(s):
1. Car cant turn. Probably something with script.

2. Some textures just disapper. When I export them there is no any folder or texture file in .dae location.
NEW 3. Car center of mass is a bit more on drivers side, that makes car flip underground when turning.

Please help me if there is way to fix that.
Script:
Code: [Select]
« Last Edit: August 05, 2016, 04:30:28 pm by OskiekSL »
Logged

SteelRat

  • Sr. Member
  • ****
  • Posts: 380
  • newbie
Re: Problem with modding vehicle
« Reply #4 on: August 05, 2016, 02:48:21 pm »

Need a source model to help.
Logged

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: Problem with modding vehicle
« Reply #5 on: August 05, 2016, 03:00:45 pm »

Hi,

I am going to assume you need to fix the joint pivots before you export the model. Wheels will rotate around the X axis for rolling forward and backward and rotate around the Z axis for turning left/right, which is done by the method this.animate_wheels(); near the bottom of the script. Other more advanced models may require you to move and rotate the wheels differently without this method using move and rotate methods, but for most models the animate_wheels method works as long as your pivots are correct.

First, make sure your model is oriented in the correct direction, where the forward vector is aligned with the +Y axis which should be pointing directly forward form the perspective of the driver, and if not you wheels will obviously be rotating around the wrong axis. If you model is already aligned correctly, then you may need to Reset Pivot Transform, and/or Align Pivot to World. I use 3ds Max, so I have no idea about how any of this is done in Sketchup, but there will be tutorials online for that. I've heard Sketchup is "better" than it used to be, but if you are serious about modelling I would recommend using Blender (which is also free), and at the very least exporting to FBX, as there are issues with Collage in general and I do not use it. FBX importer shortcut if Ctrl + F7.

Another helpful thing is to visualise the joint pivots in Outerra with debug keys enabled in eng.cfg ( debug_keys = true, ) using Alt + 7 keys. You'll see the main axis which is the large axis and small axis for each joint. Green vector will be Y, Red is X and Blue is Z. This can help determine if the pivots are aligned or located correctly.

If you have further issues please post a download link with your entire package and I'll take a look at it. You can use the OTX exporter from the vehicle menu in Outerra, just select your car and click the Export button.

Regards,
Uriah
Logged

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: Problem with modding vehicle
« Reply #6 on: August 05, 2016, 03:04:55 pm »

In regards to textures, you may be missing materials or textures. You may have to compress to DDS format manually using nvcompress.exe (command line interface) or something like TheCompressonator. Again, plenty of information on the forums about textures/materials, but my assumption is you are actually missing materials due to exporting the wrong material type or because of the Collada format, one of many reason I only use FBX.
Logged

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Re: Problem with modding vehicle
« Reply #7 on: August 05, 2016, 03:06:23 pm »

Hi,

I think its just something that happend to sketchup. Last time when i exported house I made, there were textures, gonna try to fix and tell you
Logged

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Re: Problem with modding vehicle
« Reply #8 on: August 07, 2016, 04:39:02 am »

Hello. I asked on SketchUp forum and they told me, that its only colors, not textures. But they dont apper in game.

This is my .mtl file:
Code: [Select]
{
"version" : 512,
"mats" : [
{
"name" : "ID1320",
"color" : ".345,0.0,0.0,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID8",
"color" : ".058,.058,.058,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID3238",
"color" : ".545,.545,.545,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1073",
"color" : ".643,.694,.729,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID13",
"color" : ".118,.118,.118,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1061",
"color" : ".157,.188,.2,.627",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1639",
"color" : ".043,.043,.043,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1079",
"color" : ".545,.545,.545,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID86",
"color" : ".518,.514,.506,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1328",
"color" : ".776,.776,.776,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID2765",
"color" : ".153,.133,.133,.718",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1131",
"color" : ".6,.6,.6,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID4228",
"color" : ".098,.098,.098,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID144",
"color" : ".043,.043,.043,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1310",
"color" : ".239,.239,.239,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID2751",
"color" : ".353,.38,.416,.255",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1087",
"color" : "0.0,0.0,0.0,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
},
{
"name" : "ID1418",
"color" : "1.0,0.0,0.0,1.0",
"f0" : ".027",
"roughness" : ".498",
"no_light" : false,
"alpha_masked" : false,
"tex_albedo" : "",
"tex_normal" : "",
"tex_roughness" : "",
"tex_opacity" : "",
"tex_reflectance" : "",
"tex_environment" : ""
}]
Logged

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Problem with modding vehicle
« Reply #9 on: August 09, 2016, 10:47:25 am »

If you exported from sketchup as a .dae and used the default importer, components can be problematic (especially with models from warehouse) as they can show up as weird color/reflections once in Outerra. You better collapse these and make groups. But sometimes even when collapsed it still can have these weird reflections.

On the other hand, the FBX importer work well with components and they import fine but any pivots you set in sketchup will be be revert to the world axis on the fbx export. So you would have to edit the pivots in another program (blender, max)
Logged

OskiekSL

  • Jr. Member
  • *
  • Posts: 12
Re: Problem with modding vehicle
« Reply #10 on: August 09, 2016, 10:54:17 am »

Hi,

Can you tell me if I can import kmz file or export fbx from sketchup, without any paying?
Also could you make instruction how to make it work, also how to fix error with turning and fliping on roof?
Logged

M7

  • Hero Member
  • *****
  • Posts: 736
  • newbie
Re: Problem with modding vehicle
« Reply #11 on: August 09, 2016, 11:02:56 am »

yeah you need the pro version to export as fbx. But you can still try the .dae export and make sure that there's no component left. It might work out fine.  As for the .js config, i dont really know to set it up myself.
Logged