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]

Author Topic: Importing tanks  (Read 22352 times)

murkz

  • Full Member
  • ***
  • Posts: 152
    • The Antisocial Gamer
Re: Importer
« Reply #15 on: November 14, 2012, 08:18:24 am »

Only the wheels that touch the ground are rotating with animate_wheels() currently, but you could rotate it manually via geomob. The same for the steering wheel: first call get_geomob(0) to get the geometry object, then get the joint of the steering wheel and call one of the rotate methods on it.
Code: [Select]
function init_vehicle() {
  this.geom = this.get_geomob(0);
  this.swheel = this.geom.get_joint("your steering wheel node");
}

function update_frame(...){
  ...
  this.geom.rotate_joint_orig(this.swheel, angle, {x:0,y:0,z:1});
}
This assumes you have the steering wheel as an object with rotation axis aligned with z, change if needed.


Hi Cameni,

I have tried the code but get a unexpected token error, line 110

I have no clue what that means :) as I am a scripting noob...

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Importing tanks
« Reply #16 on: November 14, 2012, 09:37:32 am »

Please post what's in your script on line 110 (+- a few lines around).
Logged

Oldtown

  • Member
  • **
  • Posts: 77
  • newbie
Re: Importing tanks
« Reply #17 on: April 08, 2013, 02:56:43 pm »

Hello guys ... i am stuck on scripting a driving tank.

I can move foward and backward but turning is a book with seven seals. I am not a real pro on scripting so I could really need some help.

Quote
//vehicle script file
//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
   
    var wheelparam = {
    radius: 0.25,
    width: 0.2,
    suspension_max: 0.2,
    suspension_min: -0.2,
    suspension_stiffness: 3.0,
    damping_compression: 0.05,
    damping_relaxation: 0.2,
    slip: 0.8,
    roll_influence: 0.1
  };
       
        this.add_wheel('wl_01',wheelparam);
        this.add_wheel('wl_02',wheelparam);
        this.add_wheel('wl_03',wheelparam);
        this.add_wheel('wl_04',wheelparam);
        this.add_wheel('wl_05',wheelparam);
        this.add_wheel('wl_06',wheelparam);
        this.add_wheel('wl_07',wheelparam);
        this.add_wheel('wl_08',wheelparam);
        this.add_wheel('wl_09',wheelparam);
   
        this.add_wheel('wr_01',wheelparam);
        this.add_wheel('wr_02',wheelparam);
        this.add_wheel('wr_03',wheelparam);
        this.add_wheel('wr_04',wheelparam);
        this.add_wheel('wr_05',wheelparam);
        this.add_wheel('wr_06',wheelparam);
        this.add_wheel('wr_07',wheelparam);
        this.add_wheel('wr_08',wheelparam);
        this.add_wheel('wr_09',wheelparam);
   
   return {mass:71700, com:{y:-0.55},};
}

//invoked for each new instance of the vehicle
function init_vehicle(){
}

//invoked when engine starts or stops
function engine(start){
}

//invoked each frame to handle the inputs and animate the model

const EF = 7000.0;
const BF = 40000.0;
const maxkmh = 34;
const forceloss = EF / (0.2*maxkmh + 1);

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.6;
   
  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);
  this.wheel_force(8, engine);
  this.wheel_force(9, engine);
  this.wheel_force(10, engine);
  this.wheel_force(11, engine);
  this.wheel_force(12, engine);
  this.wheel_force(13, engine);
  this.wheel_force(14, engine);
  this.wheel_force(15, engine);
  this.wheel_force(16, engine);
  this.wheel_force(17, engine);
 
  brake *= BF;
  this.wheel_brake(-1, brake);
 
  this.animate_wheels();
}

Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Importing tanks
« Reply #18 on: April 08, 2013, 03:08:30 pm »

Here I've got one tank script with turning, done for another user (murkz), it may be helpful for you:

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

//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
  var wheelparam = {
    radius: 0.46,
    width: 0.20,
    suspension_max: 0.2,
    suspension_min: -0.35,
    //ride height   
    suspension_stiffness: 3.0,

    damping_compression: 0.2,
    damping_relaxation: 0.12,
    slip: 0.5,
    roll_influence: 0.1
  //rotation: -1
  };
  this.add_wheel('wheel1', wheelparam);
  this.add_wheel('wheel2', wheelparam);
  this.add_wheel('wheel3', wheelparam);
  this.add_wheel('wheel4', wheelparam);
  this.add_wheel('wheel5', wheelparam);
  this.add_wheel('wheel6', wheelparam);
  this.add_wheel('wheel7', wheelparam);
  this.add_wheel('wheel8', wheelparam); 
  this.add_wheel('wheel9', wheelparam);
  this.add_wheel('wheel10', wheelparam);
  this.add_wheel('wheel11', wheelparam);
  this.add_wheel('wheel12', wheelparam);
  this.add_wheel('wheel13', wheelparam);
  this.add_wheel('wheel14', wheelparam);
  this.add_wheel('wheel15', wheelparam);
  this.add_wheel('wheel16', wheelparam);
  return {mass:7530, steering:2.0, steering_ecf:60, centering: 10, centering_ecf:20};
}

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

//invoked when engine starts or stops
function engine(start){
}


const EF = 10000.0;
const BF = 4000.0;
const maxkmh = 50;
const forceloss = EF / (0.2*maxkmh + 1);

//invoked each frame to handle the 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;
   
  var el = steering>0 ? 0 : engine;
  var er = steering<0 ? 0 : engine;

  this.wheel_force(0, el);
  this.wheel_force(2, el);
  this.wheel_force(4, el);
  this.wheel_force(6, el);
  this.wheel_force(8, el);
  this.wheel_force(10, el);
  this.wheel_force(12, el);
  this.wheel_force(14, el);
   
  this.wheel_force(1, er);
  this.wheel_force(3, er);
  this.wheel_force(5, er);
  this.wheel_force(7, er);
  this.wheel_force(9, er);
  this.wheel_force(11, er);     
  this.wheel_force(13, er);
  this.wheel_force(15, er);
   
  brake *= BF;
  var bl = steering>0 ? BF*steering : 0;
  var br = steering<0 ? -BF*steering : 0;
  bl += brake;
  br += brake;
 
  this.wheel_brake(0, bl);
  this.wheel_brake(2, bl);
  this.wheel_brake(4, bl);
  this.wheel_brake(6, bl);
  this.wheel_brake(8, bl);
  this.wheel_brake(10, bl);
  this.wheel_brake(12, bl);
  this.wheel_brake(14, bl);
   
  this.wheel_brake(1, br);
  this.wheel_brake(3, br);
  this.wheel_brake(5, br);
  this.wheel_brake(7, br);
  this.wheel_brake(9, br);
  this.wheel_brake(11, br);     
  this.wheel_brake(13, br);
  this.wheel_brake(15, br);

  this.animate_wheels();
}
Logged

Oldtown

  • Member
  • **
  • Posts: 77
  • newbie
Re: Importing tanks
« Reply #19 on: April 08, 2013, 03:26:14 pm »

thank you very much ... I gotta eat now and then I will get through this step by step to understand what is happening there. Appreciate your help very much!
Logged

Oldtown

  • Member
  • **
  • Posts: 77
  • newbie
Re: Importing tanks
« Reply #20 on: April 15, 2013, 02:47:23 am »

After some days spending with the band and work I got the time to try out the script.
Indeed it works .... the wheels move now in the correct way if I want to turn and it turns. But verrrrryyyy slow. I moved up const EF up to 40000 but still it turns slow. I played around with the mass and with the wheelparam but nothing helps ... did I make a mistake in 3D Max??!?!
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Importing tanks
« Reply #21 on: April 15, 2013, 02:55:40 am »

I believe the problem is in the missing separation between lateral and longitudinal friction. There's just some hardwired internal coefficient, roughly set for normal tires, but for tank tracks it must be a much higher difference, easier for tracks to slide sideways. I'm going to expose the coefficient in the configuration somewhere.
Logged

ZeosPantera

  • ||>>-Z-<<||
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2520
  • #1 Outerra Fan Boy
    • My Youtube
Re: Importing tanks
« Reply #22 on: April 15, 2013, 03:20:01 am »

So he needs to lower his slip values. When I coded tanks in garrys mod I made it so static turns were granted more power than just going strait or turning while moving forward. I am sure you could hack that in there.
Logged
"Fear accompanies the possibility of death, Calm shepherds its certainty" - General Ka Dargo

Oldtown

  • Member
  • **
  • Posts: 77
  • newbie
Re: Importing tanks
« Reply #23 on: April 15, 2013, 05:12:52 am »

I tried this allready ^^ was funny to see a 70 tons Jagdtiger slipping around like a block of ice. You cant even brake if you want  :o
Logged
Pages: 1 [2]