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

Author Topic: turret assistance  (Read 2230 times)

zzz

  • Sr. Member
  • ****
  • Posts: 266
  • newbie
turret assistance
« on: June 07, 2014, 04:22:24 pm »

Animating my first turret and having some issues.



I've added two animations to the model, one where the middle segment (called "yaw") rotates laterally, and one where the main gun bit (called "pitch") pitches vertically. The base has no animations. The main gun's pivot is a child to the mid section, so that it rotates along with the rest of the model.

Imported it as a vehicle and used this JS code:

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

const MaxTurretXSpeed = 5; //deg/s
const MaxTurretYSpeed = 5; //deg/s
const MaxTurretXAccel = 100;//deg/s^2
const MaxTurretYAccel = 100;//deg/s^2
const MinTurretAngle = -8;  //in deg  gun depression
const TurretAngleSpan = 90; //in deg  gun elevation
const TurningBoost = 0.4;   //boost coefficient to help with turning at speed
const TurnForceCoef = 0.8;  //portion of engine force for neutral turns
const RollingFriction = 1000;//force that needs to be overcome to get wheels turning
const EF = 25000.0;         //engine force
const BF = 20000.0;         //braking force
const EFr = 0.02;           //engine force reduction coef with speed
const maxkmh = 40;          //top speed


function radians(v){
  return v*Math.PI/180.0;
}


//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
 
  var geom = this.get_geomob(0);
  turret = geom.get_joint('yaw');
  mantlet = geom.get_joint('pitch');
 
  return {mass:11500, com:{z:0.5,y:0.5}, steering:2.0, steering_ecf:60, centering: 100, centering_ecf:20,
    turretx_speed: radians(MaxTurretXSpeed),
    turrety_speed: MaxTurretYSpeed/TurretAngleSpan,
    turretx_accel: radians(MaxTurretXAccel),
    turrety_accel: MaxTurretYAccel/TurretAngleSpan,
  };
}

//invoked for each new instance of the vehicle
function init_vehicle(){
  this.set_fps_camera_pos({x:-0.5,y:0.00,z:3.40});
  this.snd = this.sound();
  this.geom = this.get_geomob(0);
  this.turx = this.tury = 0.0;
}

//invoked when engine starts or stops

//handle extra actions
function action(k,v,dt)
{
  switch(k){
  case ATurretX: this.geom.rotate_joint_orig(turret, v, {x:0,y:0,z:-1}); break;
  case ATurretY: this.geom.rotate_joint_orig(mantlet, radians(TurretAngleSpan*0.5*(1+v)+MinTurretAngle), {x:1,y:0,z:0}); break;
  }
}

const forceloss = 1.0 / (EFr*maxkmh + 1);

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering)
{
 
}

In Outerra the rotate keys rotate the midsection instaneously +/- 15 degrees and no more, and leave the main gun floating in midair. The main gun doesn't pitch at all.

I've uploaded the DAE file I used. Can anyone help?
https://www.mediafire.com/?98ce3shqxoxj2gc
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6663
  • Pegs is clever, but tae hain’t a touch sentimental
    • outerra.com
Re: turret assistance
« Reply #1 on: June 08, 2014, 06:03:33 am »

You seem to be using an old version of murkz's Luchs script code, aren't you? turretx_speed etc do not have any effect in the returned vehicle parameters from init_chassis.

You should use his latest version, it's got smooth yaw/pitch movement with limits implemented. Or send me the otx file, I can code it in quickly.
Logged

zzz

  • Sr. Member
  • ****
  • Posts: 266
  • newbie
Re: turret assistance
« Reply #2 on: June 08, 2014, 06:24:17 am »

Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6663
  • Pegs is clever, but tae hain’t a touch sentimental
    • outerra.com
Re: turret assistance
« Reply #3 on: June 08, 2014, 07:12:29 am »

The geometry hierarchy seems to be wrong. I can only get some side parts turning, and only on the "yaw001" node.

Here's the fixed script for smooth movement, but somebody has to help you with setting up the hierarchy:
Code: [Select]
//vehicle script file
//see http://xtrac.outerra.com/index.fcgi/wiki/vehicle for example and documentation
var turret,mantlet;

const MaxTurretXSpeed = 5; //deg/s
const MaxTurretYSpeed = 5; //deg/s
const MaxTurretXAccel = 100;//deg/s^2
const MaxTurretYAccel = 100;//deg/s^2
const MinTurretAngle = -8;  //in deg  gun depression
const MaxTurretAngle = 90;  //in deg  gun elevation
const EF = 25000.0;         //engine force
const BF = 20000.0;         //braking force
const EFr = 0.02;           //engine force reduction coef with speed
const maxkmh = 40;          //top speed


function radians(v){
  return v*Math.PI/180.0;
}


//invoked only the first time the model is loaded, or upon reload
function init_chassis(){
 
  var geom = this.get_geomob(0);
  turret = geom.get_joint('yaw001');//geom.get_joint('yaw');
  mantlet = geom.get_joint('pitch');
 
  return {mass:11500, com:{z:0.5,y:0.5}, steering:2.0, steering_ecf:60, centering: 100, centering_ecf:20};
}

//invoked for each new instance of the vehicle
function init_vehicle(){
  this.set_fps_camera_pos({x:-0.5,y:0.00,z:3.40});
  this.snd = this.sound();
  this.geom = this.get_geomob(0);

  this.turx = new axis_integrator(radians(MaxTurretXSpeed), radians(MaxTurretXAccel));
  this.tury = new axis_integrator(radians(MaxTurretYSpeed), radians(MaxTurretYAccel), radians(MinTurretAngle), radians(MaxTurretAngle));
}

//invoked when engine starts or stops

//handle extra actions
function action(k,v,dt)
{
  switch(k){
  case ATurretX: this.turx.set(v); break;
  case ATurretY: this.tury.set(v); break;
  }
}

const forceloss = 1.0 / (EFr*maxkmh + 1);

//invoked each frame to handle the inputs and animate the model
function update_frame(dt, engine, brake, steering)
{
  if(this.turx.changed(dt)) this.geom.rotate_joint_orig(turret, this.turx.value, {z:-1});
  if(this.tury.changed(dt)) this.geom.rotate_joint_orig(mantlet, this.tury.value, {x:1});
}
Logged

zzz

  • Sr. Member
  • ****
  • Posts: 266
  • newbie
Re: turret assistance
« Reply #4 on: June 08, 2014, 06:29:12 pm »

all working now, thanks.
Logged