/**
Simulate drag
- self.velocity = movelib_dragvec(self.velocity,0.02,0.5);
+ this.velocity = movelib_dragvec(this.velocity,0.02,0.5);
**/
-vector movelib_dragvec(float drag, float exp_)
-{SELFPARAM();
+vector movelib_dragvec(entity this, float drag, float exp_)
+{
float lspeed,ldrag;
- lspeed = vlen(self.velocity);
+ lspeed = vlen(this.velocity);
ldrag = lspeed * drag;
ldrag = ldrag * (drag * exp_);
ldrag = 1 - (ldrag / lspeed);
- return self.velocity * ldrag;
+ return this.velocity * ldrag;
}
/**
Simulate drag
- self.velocity *= movelib_dragflt(somespeed,0.01,0.7);
+ this.velocity *= movelib_dragflt(somespeed,0.01,0.7);
**/
float movelib_dragflt(float fspeed,float drag,float exp_)
{
/**
Do a inertia simulation based on velocity.
Basicaly, this allows you to simulate loss of steering with higher speed.
- self.velocity = movelib_inertmove_byspeed(self.velocity,newvel,1000,0.1,0.9);
+ this.velocity = movelib_inertmove_byspeed(this.velocity,newvel,1000,0.1,0.9);
**/
-vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
-{SELFPARAM();
+vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max,float newmin,float oldmax)
+{
float influense;
- influense = vlen(self.velocity) * (1 / vel_max);
+ influense = vlen(this.velocity) * (1 / vel_max);
influense = bound(newmin,influense,oldmax);
- return (vel_new * (1 - influense)) + (self.velocity * influense);
+ return (vel_new * (1 - influense)) + (this.velocity * influense);
}
-vector movelib_inertmove(vector new_vel,float new_bias)
-{SELFPARAM();
- return new_vel * new_bias + self.velocity * (1-new_bias);
+vector movelib_inertmove(entity this, vector new_vel,float new_bias)
+{
+ return new_vel * new_bias + this.velocity * (1-new_bias);
}
-void movelib_move(vector force,float max_velocity,float drag,float theMass,float breakforce)
-{SELFPARAM();
+void movelib_move(entity this, vector force,float max_velocity,float drag,float theMass,float breakforce)
+{
float deltatime;
float acceleration;
float mspeed;
vector breakvec;
- deltatime = time - self.movelib_lastupdate;
+ deltatime = time - this.movelib_lastupdate;
if (deltatime > 0.15) deltatime = 0;
- self.movelib_lastupdate = time;
+ this.movelib_lastupdate = time;
if (!deltatime) return;
- mspeed = vlen(self.velocity);
+ mspeed = vlen(this.velocity);
if (theMass)
acceleration = vlen(force) / theMass;
else
acceleration = vlen(force);
- if (IS_ONGROUND(self))
+ if (IS_ONGROUND(this))
{
if (breakforce)
{
- breakvec = (normalize(self.velocity) * (breakforce / theMass) * deltatime);
- self.velocity = self.velocity - breakvec;
+ breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime);
+ this.velocity = this.velocity - breakvec;
}
- self.velocity = self.velocity + force * (acceleration * deltatime);
+ this.velocity = this.velocity + force * (acceleration * deltatime);
}
if (drag)
- self.velocity = movelib_dragvec(drag, 1);
+ this.velocity = movelib_dragvec(this, drag, 1);
- if (self.waterlevel > 1)
+ if (this.waterlevel > 1)
{
- self.velocity = self.velocity + force * (acceleration * deltatime);
- self.velocity = self.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
+ this.velocity = this.velocity + force * (acceleration * deltatime);
+ this.velocity = this.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
}
else
- self.velocity = self.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
+ this.velocity = this.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
- mspeed = vlen(self.velocity);
+ mspeed = vlen(this.velocity);
if (max_velocity)
if (mspeed > max_velocity)
- self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
+ this.velocity = normalize(this.velocity) * (mspeed - 50);//* max_velocity;
}
/*
.float buoyancy;
float movelib_deltatime;
-void movelib_startupdate()
+void movelib_startupdate(entity this)
{
- movelib_deltatime = time - self.movelib_lastupdate;
+ movelib_deltatime = time - this.movelib_lastupdate;
if (movelib_deltatime > 0.5)
movelib_deltatime = 0;
- self.movelib_lastupdate = time;
+ this.movelib_lastupdate = time;
}
-void movelib_update(vector dir,float force)
+void movelib_update(entity this, vector dir,float force)
{
vector acceleration;
float old_speed;
if(!movelib_deltatime)
return;
- v_z = self.velocity_z;
- old_speed = vlen(self.velocity);
- old_dir = normalize(self.velocity);
+ v_z = this.velocity_z;
+ old_speed = vlen(this.velocity);
+ old_dir = normalize(this.velocity);
- //ggravity = (autocvar_sv_gravity / self.mass) * '0 0 100';
- acceleration = (force / self.mass) * dir;
- //acceleration -= old_dir * (old_speed / self.mass);
+ //ggravity = (autocvar_sv_gravity / this.mass) * '0 0 100';
+ acceleration = (force / this.mass) * dir;
+ //acceleration -= old_dir * (old_speed / this.mass);
acceleration -= ggravity;
- if(self.waterlevel > 1)
+ if(this.waterlevel > 1)
{
- ffriction = self.water_friction;
- acceleration += self.buoyancy * '0 0 1';
+ ffriction = this.water_friction;
+ acceleration += this.buoyancy * '0 0 1';
}
else
- if(IS_ONGROUND(self))
- ffriction = self.ground_friction;
+ if(IS_ONGROUND(this))
+ ffriction = this.ground_friction;
else
- ffriction = self.air_friction;
+ ffriction = this.air_friction;
acceleration *= ffriction;
- //self.velocity = self.velocity * (ffriction * movelib_deltatime);
- self.velocity += acceleration * movelib_deltatime;
- self.velocity_z = v_z;
+ //this.velocity = this.velocity * (ffriction * movelib_deltatime);
+ this.velocity += acceleration * movelib_deltatime;
+ this.velocity_z = v_z;
}
*/
this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate);
//a = this.origin;
- setorigin(this,r);
+ setorigin(this, r);
}