/**
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;
}
*/
**/
#endif
-void movelib_groundalign4point(float spring_length, float spring_up, float blendrate, float _max)
-{SELFPARAM();
+void movelib_groundalign4point(entity this, float spring_length, float spring_up, float blendrate, float _max)
+{
vector a, b, c, d, e, r, push_angle, ahead, side;
push_angle.y = 0;
- r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
+ r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up);
e = v_up * spring_length;
// Put springs slightly inside bbox
- ahead = v_forward * (self.maxs.x * 0.8);
- side = v_right * (self.maxs.y * 0.8);
+ ahead = v_forward * (this.maxs.x * 0.8);
+ side = v_right * (this.maxs.y * 0.8);
a = r + ahead + side;
b = r + ahead - side;
c = r - ahead + side;
d = r - ahead - side;
- traceline(a, a - e,MOVE_NORMAL,self);
+ traceline(a, a - e,MOVE_NORMAL,this);
a.z = (1 - trace_fraction);
r = trace_endpos;
- traceline(b, b - e,MOVE_NORMAL,self);
+ traceline(b, b - e,MOVE_NORMAL,this);
b.z = (1 - trace_fraction);
r += trace_endpos;
- traceline(c, c - e,MOVE_NORMAL,self);
+ traceline(c, c - e,MOVE_NORMAL,this);
c.z = (1 - trace_fraction);
r += trace_endpos;
- traceline(d, d - e,MOVE_NORMAL,self);
+ traceline(d, d - e,MOVE_NORMAL,this);
d.z = (1 - trace_fraction);
r += trace_endpos;
a.x = r.z;
- r = self.origin;
+ r = this.origin;
r.z = r.z;
push_angle.x = (a.z - c.z) * _max;
push_angle.z = (b.z - a.z) * _max;
push_angle.z += (d.z - c.z) * _max;
- //self.angles_x += push_angle_x * 0.95;
- //self.angles_z += push_angle_z * 0.95;
+ //this.angles_x += push_angle_x * 0.95;
+ //this.angles_z += push_angle_z * 0.95;
- self.angles_x = ((1-blendrate) * self.angles.x) + (push_angle.x * blendrate);
- self.angles_z = ((1-blendrate) * self.angles.z) + (push_angle.z * blendrate);
+ this.angles_x = ((1-blendrate) * this.angles.x) + (push_angle.x * blendrate);
+ this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate);
- //a = self.origin;
- setorigin(self,r);
+ //a = this.origin;
+ setorigin(this, r);
}