Outerra forum

Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => JavaScript development => Topic started by: zzz on September 19, 2015, 06:41:18 pm

Title: axis_integrator
Post by: zzz on September 19, 2015, 06:41:18 pm
It seems the axis_integrator function no longer exists, which is a bit worrying as it's key to turret functionality  :-[
Title: Re: axis_integrator
Post by: cameni on September 20, 2015, 02:25:04 am
Axis integrator was just a piece of js injected into vehicle scripts. To use it, simply include this code:

Code: [Select]
function axis_integrator(maxspeed,maxaccel,clamp_min,clamp_max){
  this.mac = maxaccel ? maxaccel : 1.0;
  this.msp = maxspeed;
  this.speed = 0;
  this.value = 0;
  this.targ = 0;
  this.cmin = clamp_min!=undefined ? clamp_min : Number.NEGATIVE_INFINITY;
  this.cmax = clamp_max!=undefined ? clamp_max : Number.POSITIVE_INFINITY;
}

axis_integrator.prototype.set = function(v){this.targ = v}
axis_integrator.prototype.set_max_speed = function(v){this.msp = v}
axis_integrator.prototype.changed = function(dt){
  var ob = this.speed;
  var dm = this.mac*dt;
  if(this.targ > ob+dm)
    this.speed += dm;
  else if(this.targ < ob-dm)
    this.speed -= dm;
  else
    this.speed = this.targ;
  var ov = this.value;
  this.value += this.speed*this.msp*dt;
  if(this.value < this.cmin) this.value = this.cmin;
  if(this.value > this.cmax) this.value = this.cmax;
  return ov != this.value;
}
Title: Re: axis_integrator
Post by: zzz on September 20, 2015, 09:06:11 am
Thanks. It is working now. What values does the direction float3 {x:0.0,y:0.0,z:0.0} field of this.fire take? I know they're the same setup as the spotlight directions but as mine only needed orthog angles I got past them without really understanding them. Some direction values make the projectile speed and size really big or small.
Title: Re: axis_integrator
Post by: cameni on September 20, 2015, 12:02:01 pm
Absolute value of the dir vector multiplies the speed, so you should keep it a unit vector (but that wasn't intended, I'll normalize it). It should not affect the size though.