2 #include "../dpdefs/csprogsdefs.qh"
5 #include "../dpdefs/progsdefs.qh"
6 #include "../dpdefs/dpextensions.qh"
7 #include "../csqcmodellib/sv_model.qh"
15 self.velocity = movelib_dragvec(self.velocity,0.02,0.5);
17 vector movelib_dragvec(float drag, float exp_)
21 lspeed = vlen(self.velocity);
22 ldrag = lspeed * drag;
23 ldrag = ldrag * (drag * exp_);
24 ldrag = 1 - (ldrag / lspeed);
26 return self.velocity * ldrag;
31 self.velocity *= movelib_dragflt(somespeed,0.01,0.7);
33 float movelib_dragflt(float fspeed,float drag,float exp_)
37 ldrag = fspeed * drag;
38 ldrag = ldrag * ldrag * exp_;
39 ldrag = 1 - (ldrag / fspeed);
45 Do a inertia simulation based on velocity.
46 Basicaly, this allows you to simulate loss of steering with higher speed.
47 self.velocity = movelib_inertmove_byspeed(self.velocity,newvel,1000,0.1,0.9);
49 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
53 influense = vlen(self.velocity) * (1 / vel_max);
55 influense = bound(newmin,influense,oldmax);
57 return (vel_new * (1 - influense)) + (self.velocity * influense);
60 vector movelib_inertmove(vector new_vel,float new_bias)
62 return new_vel * new_bias + self.velocity * (1-new_bias);
65 .float movelib_lastupdate;
66 void movelib_move(vector force,float max_velocity,float drag,float theMass,float breakforce)
73 deltatime = time - self.movelib_lastupdate;
74 if (deltatime > 0.15) deltatime = 0;
75 self.movelib_lastupdate = time;
76 if (!deltatime) return;
78 mspeed = vlen(self.velocity);
81 acceleration = vlen(force) / theMass;
83 acceleration = vlen(force);
85 if (self.flags & FL_ONGROUND)
89 breakvec = (normalize(self.velocity) * (breakforce / theMass) * deltatime);
90 self.velocity = self.velocity - breakvec;
93 self.velocity = self.velocity + force * (acceleration * deltatime);
97 self.velocity = movelib_dragvec(drag, 1);
99 if (self.waterlevel > 1)
101 self.velocity = self.velocity + force * (acceleration * deltatime);
102 self.velocity = self.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
105 self.velocity = self.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
107 mspeed = vlen(self.velocity);
110 if (mspeed > max_velocity)
111 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
116 .float side_friction;
117 .float ground_friction;
119 .float water_friction;
121 float movelib_deltatime;
123 void movelib_startupdate()
125 movelib_deltatime = time - self.movelib_lastupdate;
127 if (movelib_deltatime > 0.5)
128 movelib_deltatime = 0;
130 self.movelib_lastupdate = time;
133 void movelib_update(vector dir,float force)
144 if(!movelib_deltatime)
146 v_z = self.velocity_z;
147 old_speed = vlen(self.velocity);
148 old_dir = normalize(self.velocity);
150 //ggravity = (autocvar_sv_gravity / self.mass) * '0 0 100';
151 acceleration = (force / self.mass) * dir;
152 //acceleration -= old_dir * (old_speed / self.mass);
153 acceleration -= ggravity;
155 if(self.waterlevel > 1)
157 ffriction = self.water_friction;
158 acceleration += self.buoyancy * '0 0 1';
161 if(self.flags & FL_ONGROUND)
162 ffriction = self.ground_friction;
164 ffriction = self.air_friction;
166 acceleration *= ffriction;
167 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
168 self.velocity += acceleration * movelib_deltatime;
169 self.velocity_z = v_z;
175 void movelib_move_simple(vector newdir,float velo,float blendrate)
177 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
180 #define movelib_move_simple(newdir,velo,blendrate) \
181 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo
183 #define movelib_move_simple_gravity(newdir,velo,blendrate) \
184 if(self.flags & FL_ONGROUND) movelib_move_simple(newdir,velo,blendrate)
186 void movelib_beak_simple(float force)
192 mspeed = max(0,vlen(self.velocity) - force);
193 mdir = normalize(self.velocity);
194 vz = self.velocity.z;
195 self.velocity = mdir * mspeed;
196 self.velocity_z = vz;
200 Pitches and rolls the entity to match the gound.
201 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
205 void movelib_groundalign4point(float spring_length, float spring_up, float blendrate, float _max)
207 vector a, b, c, d, e, r, push_angle, ahead, side;
210 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
211 e = v_up * spring_length;
213 // Put springs slightly inside bbox
214 ahead = v_forward * (self.maxs.x * 0.8);
215 side = v_right * (self.maxs.y * 0.8);
217 a = r + ahead + side;
218 b = r + ahead - side;
219 c = r - ahead + side;
220 d = r - ahead - side;
222 traceline(a, a - e,MOVE_NORMAL,self);
223 a_z = (1 - trace_fraction);
226 traceline(b, b - e,MOVE_NORMAL,self);
227 b_z = (1 - trace_fraction);
230 traceline(c, c - e,MOVE_NORMAL,self);
231 c_z = (1 - trace_fraction);
234 traceline(d, d - e,MOVE_NORMAL,self);
235 d_z = (1 - trace_fraction);
242 push_angle_x = (a.z - c.z) * _max;
243 push_angle.x += (b.z - d.z) * _max;
245 push_angle_z = (b.z - a.z) * _max;
246 push_angle.z += (d.z - c.z) * _max;
248 //self.angles_x += push_angle_x * 0.95;
249 //self.angles_z += push_angle_z * 0.95;
251 self.angles_x = ((1-blendrate) * self.angles.x) + (push_angle.x * blendrate);
252 self.angles_z = ((1-blendrate) * self.angles.z) + (push_angle.z * blendrate);