Anteworld - Outerra Game > Modding: Importer, Tools & Utilities

bicycle model working !

(1/4) > >>

fly77:
I got my bicycle model working. Moving pedals included, no light yet and just simple pedal sound. https://www.dropbox.com/sh/269zknt2a5sc5mc/AADd6Q-hGj1-s0L8KI_iKNzca?dl=0. Also since the rotation axis of the steering wheel is inclined while the steering axis of the front wheel is vertical some misaligment develops when steering. I set the origin of rotation of both frontwheel and steering wheel to the same point in blender but  I don't know how to impose a "inclined" front wheel steering axis. Anyway its still fine and a lot of fun to ride.
The more serious problem though is that I can spawn just a single instance of the the bike. The second one will not spawn, giving the following error: 

23:34:38.650 ERROR: vehicle::init_vehicle: file:///Outerra/packages/fly77/bike1/bike1.js(87): TypeError: Cannot call method 'get_joint' of undefined (ot::js::vehicle_physics.init_vehicle(): )

here os the javascript
--- Code: ---
var EF = 250.0;                   
var BF = 1530.0;                       
var ST = 0.7;                         
var maxkmh = 50;                     
var forceloss = EF / (0.2*maxkmh + 1); 

var Wh_rad = 0.33;   //<-- wheel radius, adjust if tires appear above or below the road
var CarMass = 125;                     

var WHEEL_FR = "WHEEL-FR";           
var WHEEL_FL = "WHEEL-FL";
var WHEEL_RR = "WHEEL-RR";
var WHEEL_RL = "WHEEL-RL";
var STEERING_WHEEL = "STEER-WHEEL";
var WHEEL_PEDAL= "PEDAL";



       
var steerAngle;                           

var swheel_id; 

var _snd = -1;
var _snd_src = -1;

var _src_on = 0;
var _snd_on = 0;

var soundfile1 = "pedala.ogg" ;            //<-- sound file
var soundfile2 = "partenza.ogg"  ;           //<-- sound file



function init_chassis()
{
  var wheelparam = {
    radius: Wh_rad,             
    width: 0.05,             
    suspension_max: 0.1,
    suspension_min: -0.12,
    suspension_stiffness: 18.0,
    damping_compression: 0.4,
    damping_relaxation: 0.12,
    grip: 0.2,
    roll_influence: 0.1};

   
    this.add_wheel(WHEEL_FR,wheelparam);   
    this.add_wheel(WHEEL_FL,wheelparam);
    this.add_wheel(WHEEL_RR,wheelparam);
    this.add_wheel(WHEEL_RL,wheelparam);
    this.geom = this.get_geomob(0)
    swheel_id = this.geom.get_joint(STEERING_WHEEL);

    _snd = this.load_sound(soundfile1);
    _snd_src = this.add_sound_emitter(WHEEL_FR );

    _snd_on = this.load_sound(soundfile1);
    _src_on = this.add_sound_emitter(WHEEL_FR );


   
 return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 9.6, centering_ecf:1, com:{x:0.4,y:0.03}};
//return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}


//------------------------------------------------------------------------------------------------
function init_vehicle(){
    this.set_fps_camera_pos({x:-0.1,y:-0.80,z:1.50});

    this.snd = this.sound();

    this.snd.set_ref_distance(0, 3.0);
    this.snd.set_ref_distance(_src_on, 3.0);
   
    this.started = 0;

    pedal = this.geom.get_joint(WHEEL_PEDAL);
}

//-----------------------------------------------------------------
function engine(start){
  if(start) {
    this.snd.play(_snd_src, _snd, false, false);
   
    this.started=1;
  }
}


//==================================================================

function update_frame(dt, engine, brake, steering)
{
  var kmh = this.speed()*3.6;
  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;
  brake *= BF;
 
  steering *= ST; 
  this.steer(-2, steering);          // -2 = front wheels used for steering
  steerAngle = steering *= 1;
  this.geom.rotate_joint_orig(swheel_id, steerAngle, {x:-0.34202,y:0.0,z:0.939693});
 
  this.wheel_force(2, engine); 
  this.wheel_force(3, engine); 

  this.wheel_brake(2, brake);   
  this.wheel_brake(3, brake); 
  this.animate_wheels();


if(this.started==1 && !this.snd.is_playing(0)) {
    this.started=2;
    this.snd.play_loop(_src_on, _snd_on);
  }
  else if(this.started==2) {
    var pitch = Math.abs(kmh)/2.0;
    var g = kmh>0 ? Math.floor(pitch) : 0;
    var f = pitch - g;
    f += 0.5*g;
    this.snd.set_pitch(_src_on, 0.5*f + 1.0);
  }

if(kmh<2){
   this.snd.stop(_src_on);
   this.started=1;
}

this.geom.rotate_joint(pedal, dt*kmh/3.0, {x:0,y:1,z:0});
}


--- End code ---


and here the object definition file


--- Code: ---
{
"obj" : "bike1",
"matlib" : "bike1",
"lod_curve" : 850.0,
"lod_curve1" : 300.0,
"physics" : "vehicle",
"script" : "bike1.js",
"strict" : false,
"description" : "",
"parameters" : "",
"fdm_root_dir" : "",
"tags" : "",
"variants" : []}

--- End code ---

Any idea what causes this problem ?

patmarrnc:
awesome! Can't wait to try it! Thanks for making the OTX available!

cameni:
init_chassis is called only once, on the first vehicle, to initialize script variables that are constant across all instances of the vehicle. It makes sense to get all joint/bone ids there, since they are not changing per instance, and store them in global variables. You should not store any this.variables there, because only the first vehicle instance will have it.

So the problem is that you also store this.geom there. The second vehicle only calls init_vehicle and doesn't have it.

fly77:
Done. Now I can spawn any number of instances. Thanks !  Updated otx.

patmarrnc:
would you consider making the model itself available for download? I'd like to see if I can smooth out the segmented look in all of the arcs. Also I'd like to see if changes to the geometry of the bike fix the problem with the front wheel's asymmetry with the forks and fender. If I manage to accomplish anything, I'll post my revisions

Navigation

[0] Message Index

[#] Next page

Go to full version