6 self.velocity = movelib_dragvec(self.velocity,0.02,0.5);
8 vector movelib_dragvec(float drag, float exp_)
12 lspeed = vlen(self.velocity);
13 ldrag = lspeed * drag;
14 ldrag = ldrag * (drag * exp_);
15 ldrag = 1 - (ldrag / lspeed);
17 return self.velocity * ldrag;
22 self.velocity *= movelib_dragflt(somespeed,0.01,0.7);
24 float movelib_dragflt(float fspeed,float drag,float exp_)
28 ldrag = fspeed * drag;
29 ldrag = ldrag * ldrag * exp_;
30 ldrag = 1 - (ldrag / fspeed);
36 Do a inertia simulation based on velocity.
37 Basicaly, this allows you to simulate loss of steering with higher speed.
38 self.velocity = movelib_inertmove_byspeed(self.velocity,newvel,1000,0.1,0.9);
40 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
44 influense = vlen(self.velocity) * (1 / vel_max);
46 influense = bound(newmin,influense,oldmax);
48 return (vel_new * (1 - influense)) + (self.velocity * influense);
51 vector movelib_inertmove(vector new_vel,float new_bias)
53 return new_vel * new_bias + self.velocity * (1-new_bias);
56 .float movelib_lastupdate;
57 void movelib_move(vector force,float max_velocity,float drag,float theMass,float breakforce)
64 deltatime = time - self.movelib_lastupdate;
65 if (deltatime > 0.15) deltatime = 0;
66 self.movelib_lastupdate = time;
67 if (!deltatime) return;
69 mspeed = vlen(self.velocity);
72 acceleration = vlen(force) / theMass;
74 acceleration = vlen(force);
76 if (self.flags & FL_ONGROUND)
80 breakvec = (normalize(self.velocity) * (breakforce / theMass) * deltatime);
81 self.velocity = self.velocity - breakvec;
84 self.velocity = self.velocity + force * (acceleration * deltatime);
88 self.velocity = movelib_dragvec(drag, 1);
90 if (self.waterlevel > 1)
92 self.velocity = self.velocity + force * (acceleration * deltatime);
93 self.velocity = self.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
96 self.velocity = self.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
98 mspeed = vlen(self.velocity);
101 if (mspeed > max_velocity)
102 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
105 void movelib_move_simple_gravity(vector newdir,float velo,float blendrate)
107 float z_speed = self.velocity_z;
108 self.movelib_lastupdate = time;
109 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
110 self.velocity_z = z_speed * self.gravity;
113 void movelib_jump_simple(float power){
114 self.velocity_z=power;
115 self.movelib_lastupdate = time;
120 .float side_friction;
121 .float ground_friction;
123 .float water_friction;
125 float movelib_deltatime;
127 void movelib_startupdate()
129 movelib_deltatime = time - self.movelib_lastupdate;
131 if (movelib_deltatime > 0.5)
132 movelib_deltatime = 0;
134 self.movelib_lastupdate = time;
137 void movelib_update(vector dir,float force)
148 if(!movelib_deltatime)
150 v_z = self.velocity_z;
151 old_speed = vlen(self.velocity);
152 old_dir = normalize(self.velocity);
154 //ggravity = (autocvar_sv_gravity / self.mass) * '0 0 100';
155 acceleration = (force / self.mass) * dir;
156 //acceleration -= old_dir * (old_speed / self.mass);
157 acceleration -= ggravity;
159 if(self.waterlevel > 1)
161 ffriction = self.water_friction;
162 acceleration += self.buoyancy * '0 0 1';
165 if(self.flags & FL_ONGROUND)
166 ffriction = self.ground_friction;
168 ffriction = self.air_friction;
170 acceleration *= ffriction;
171 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
172 self.velocity += acceleration * movelib_deltatime;
173 self.velocity_z = v_z;
179 void movelib_move_simple(vector newdir,float velo,float blendrate)
181 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
184 #define movelib_move_simple(newdir,velo,blendrate) \
185 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo
187 void movelib_beak_simple(float force)
193 mspeed = max(0,vlen(self.velocity) - force);
194 mdir = normalize(self.velocity);
195 vz = self.velocity_z;
196 self.velocity = mdir * mspeed;
197 self.velocity_z = vz;
201 Pitches and rolls the entity to match the gound.
202 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
206 void movelib_groundalign4point(float spring_length, float spring_up, float blendrate, float _max)
208 vector a, b, c, d, e, r, push_angle, ahead, side;
211 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
212 e = v_up * spring_length;
214 // Put springs slightly inside bbox
215 ahead = v_forward * (self.maxs_x * 0.8);
216 side = v_right * (self.maxs_y * 0.8);
218 a = r + ahead + side;
219 b = r + ahead - side;
220 c = r - ahead + side;
221 d = r - ahead - side;
223 traceline(a, a - e,MOVE_NORMAL,self);
224 a_z = (1 - trace_fraction);
227 traceline(b, b - e,MOVE_NORMAL,self);
228 b_z = (1 - trace_fraction);
231 traceline(c, c - e,MOVE_NORMAL,self);
232 c_z = (1 - trace_fraction);
235 traceline(d, d - e,MOVE_NORMAL,self);
236 d_z = (1 - trace_fraction);
243 push_angle_x = (a_z - c_z) * _max;
244 push_angle_x += (b_z - d_z) * _max;
246 push_angle_z = (b_z - a_z) * _max;
247 push_angle_z += (d_z - c_z) * _max;
249 //self.angles_x += push_angle_x * 0.95;
250 //self.angles_z += push_angle_z * 0.95;
252 self.angles_x = ((1-blendrate) * self.angles_x) + (push_angle_x * blendrate);
253 self.angles_z = ((1-blendrate) * self.angles_z) + (push_angle_z * blendrate);