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