3 self.velocity = movelib_vdrag(self.velocity,0.02,0.5);
5 vector movelib_dragvec(float drag, float exp)
9 lspeed = vlen(self.velocity);
10 ldrag = lspeed * drag;
11 ldrag = ldrag * (drag * exp);
12 ldrag = 1 - (ldrag / lspeed);
14 return self.velocity * ldrag;
19 self.velocity = movelib_vdrag(somespeed,0.01,0.7);
21 float movelib_dragflt(float fspeed,float drag,float exp)
25 ldrag = fspeed * drag;
26 ldrag = ldrag * ldrag * exp;
27 ldrag = 1 - (ldrag / fspeed);
33 Do a inertia simulation based on velocity.
34 Basicaly, this allows you to simulate objects loss steering with speed.
35 self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);
37 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
41 influense = vlen(self.velocity) * (1 / vel_max);
43 influense = bound(newmin,influense,oldmax);
45 return (vel_new * (1 - influense)) + (self.velocity * influense);
48 vector movelib_inertmove(vector new_vel,float new_bias)
50 return new_vel * new_bias + self.velocity * (1-new_bias);
53 .float movelib_lastupdate;
54 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)
60 deltatime = time - self.movelib_lastupdate;
61 if (deltatime > 0.15) deltatime = 0;
62 self.movelib_lastupdate = time;
63 if(!deltatime) return;
65 //mspeed = vlen(self.velocity);
68 acceleration = vlen(force) / mass;
70 acceleration = vlen(force);
72 if(self.flags & FL_ONGROUND)
76 breakforce = 1 - ((breakforce / mass) * deltatime);
77 self.velocity = self.velocity * breakforce;
80 self.velocity = self.velocity + force * (acceleration * deltatime);
83 self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;
86 self.velocity = movelib_dragvec(drag, 1);
89 if(vlen(self.velocity) > max_velocity)
90 self.velocity = normalize(self.velocity) * max_velocity;
93 void movelib_move_simple(vector newdir,float velo,float turnrate)
97 olddir = normalize(self.velocity);
99 self.velocity = normalize(olddir + newdir * turnrate) * velo;
103 vector movelib_accelerate(float force)
107 vel = normalize(vel) * (vlen(vel) + force);
108 self.velocity = self.velocity + vel;
112 vector movelib_decelerate(float force,float mass)
118 decel = force / mass;
123 vel = normalize(vel) * max((vlen(vel) - decel),0);
124 self.velocity = self.velocity - vel;
126 if(vlen(self.velocity) < 5) self.velocity = '0 0 0';
129 vector movelib_velocity_transfer(entity source,entity destination)