Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Outerra Tech Demo download. Help with graphics driver issues

Pages: [1] 2

Author Topic: bicycle model working !  (Read 16706 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
bicycle model working !
« on: September 12, 2018, 06:38:25 pm »

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: [Select]

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



and here the object definition file

Code: [Select]

{
"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" : []}

Any idea what causes this problem ?
« Last Edit: September 12, 2018, 06:51:24 pm by fly77 »
Logged

patmarrnc

  • Full Member
  • ***
  • Posts: 136
Re: bicycle model working !
« Reply #1 on: September 12, 2018, 09:01:11 pm »

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

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: bicycle model working !
« Reply #2 on: September 13, 2018, 02:01:18 am »

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.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #3 on: September 13, 2018, 02:26:04 am »

Done. Now I can spawn any number of instances. Thanks !  Updated otx.
« Last Edit: September 13, 2018, 02:47:27 am by fly77 »
Logged

patmarrnc

  • Full Member
  • ***
  • Posts: 136
Re: bicycle model working !
« Reply #4 on: September 13, 2018, 11:08:04 am »

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
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #5 on: September 13, 2018, 12:05:10 pm »

Sure. I was thinking that for the front wheel fork I will try to incline my blender model so that the fork axis coincides with Z. Here is the blender model  https://www.dropbox.com/s/5elblg2b86hf9u3/bike1.blend?dl=0.
« Last Edit: September 13, 2018, 12:32:11 pm by fly77 »
Logged

patmarrnc

  • Full Member
  • ***
  • Posts: 136
Re: bicycle model working !
« Reply #6 on: September 13, 2018, 02:38:23 pm »

I think the angularity problem might originate with the frame. Instead of inclining the part of the frame through which the handlebars and forks are connected, make it vertical. That way your rotation becomes a simple  vector instead of a compound vector in which more than one axis moves at the same time.

Looking at the script, I don't see a way to change the vector of the wheels, so it would be simpler to change the steering vector to match the wheels. I don't have time to mess with this right now because I'm preparing for a hurricane... but in a few days I'll take a look at it. Thanks for sharing your work! I like it a lot!
Logged

KW71

  • Outerra Developer
  • Hero Member
  • *****
  • Posts: 760
  • Love OT!
Re: bicycle model working !
« Reply #7 on: September 13, 2018, 03:47:52 pm »

Thanks for this, fly77! Kudos!  :D
Logged
"A man who is contented with what he has done, will never become famous for what he will do".

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #8 on: September 13, 2018, 04:09:56 pm »

Thanks KW71.
Anybody knows how to get the horn action working ?

I had tried as stated in the "car horn?" thread  but while it gave no error I got no sound playing. So as a workaround I used the  light toggle switch action copied from the Buggy coming with the new version. It works but then I can no longer use this for light.  What would be the correct way to access/register the "horn" action ?

My code is as follows:

Code: [Select]
function init_chassis()
{
...

      _horn_snd = this.load_sound("bell.ogg");
      _horn_snd_src = this.add_sound_emitter(STEERING_WHEEL);

      act_lights_passing = this.register_switch("car/lights/passing",toggle_passing_lights_action);
....
}


function init_vehicle(){
....
     this.snd.set_ref_distance(_horn_snd_src, 10.0);
...
}

function  toggle_passing_lights_action(v,dt){
      this.snd.play(_horn_snd_src,_horn_snd, false, false);
}

« Last Edit: September 13, 2018, 06:09:19 pm by fly77 »
Logged

Bob425

  • Jr. Member
  • *
  • Posts: 45
Re: bicycle model working !
« Reply #9 on: September 14, 2018, 01:54:31 am »

That is simply brilliant, many thanks.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #10 on: September 15, 2018, 09:26:43 am »

OK by fiddling around and looking at other models actions I got the H key now working for horn without resorting to the workaround with the L key. The solution was quite simple/obvious. Seems that the name of action is the one defined in the outerra help menu for controls.  So for horn its   "car/controls/horn" and as it is not a switch but an event register it as event. Actually in the keybinding appears written as "Horn" not "horn". Similarly with other actions the names in the menu do not appear to exactly match the events/actions/switch registering code in the js file of some models (for example the BMW). It seems that   this.register_event("car/controls/Horn", horn_action); does not work while    this.register_event("car/controls/horn", horn_action);    does work. Some help please Cameni, for the exact names to use in the event/switch ...registering. Where can we find updated info on actions ?


Code: [Select]
function init_chassis()
{....
    _snd_bell = this.load_sound("bell.ogg");
    _src_bell = this.add_sound_emitter(WHEEL_FL );
    _act_horn = this.register_event("car/controls/horn", horn_action);
....}

function init_vehicle(){
....
 this.snd = this.sound();
this.snd.set_ref_distance(_src_bell, 5.0);
...
}


function horn_action(){
    this.snd.play(_src_bell,_snd_bell,false,false);
}




« Last Edit: September 15, 2018, 10:02:05 am by fly77 »
Logged

josem75

  • Sr. Member
  • ****
  • Posts: 286
  • newbie
Re: bicycle model working !
« Reply #11 on: September 15, 2018, 12:09:04 pm »

Amazing. You solved the problem  on 2 tyres vehicles!


I enjoy a lot mount cycle going down my mountains roads.
Would be posible give this so much power for going up too, like if you are Froome? xD

Thank you very much, great adition
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #12 on: September 15, 2018, 02:32:55 pm »

Hi josem75. I'm glad you enjoy the bike. Yes you can increase the extraforce in the beginning of the javascript file:

var EF = 250.0;              increase it to whatever value you like.
Logged

patmarrnc

  • Full Member
  • ***
  • Posts: 136
Re: bicycle model working !
« Reply #13 on: September 15, 2018, 03:44:53 pm »

actually, I think the original settings are pretty realistic. I put the bike in the mountains, and on hills it loses speed, much like any bike I might pedal would tend to do. Going downhill, speed picks up.

I tried to edit the script to add the horn and other things you mentioned, but apparently I missed something because upon loading the bike just hangs in the air. Any chance of reposting the OTX with your latest script changes?
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: bicycle model working !
« Reply #14 on: September 15, 2018, 04:54:04 pm »

Uploaded new .otx file to dropbox, now with bell (press horn key  h). Corrected the issue that prevented spawning multiple bikes. Please re-download from the link at the beginning of this topic. By the way regarding the fork- front wheel misalignment issue I could not solve it in any way and it seems the culprit is the
" this.animate_wheels();"
statement that does all the wheel physics modelling. If I use instead "this.geom.rotate_joint.." commands to model both wheel orientation and spinning then it's quite simple to get the fork and frontwheel aligned correctly while steering but it means that all the wheel physics and interaction with terrain needs to be written by ourselfs in a function. I'm not sure if I am able and willing to do that.
 
« Last Edit: September 15, 2018, 05:00:18 pm by fly77 »
Logged
Pages: [1] 2