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;
107 .float side_friction;
108 .float ground_friction;
110 .float water_friction;
112 float movelib_deltatime;
114 void movelib_startupdate()
116 movelib_deltatime = time - self.movelib_lastupdate;
118 if (movelib_deltatime > 0.5)
119 movelib_deltatime = 0;
121 self.movelib_lastupdate = time;
124 void movelib_update(vector dir,float force)
135 if(!movelib_deltatime)
137 v_z = self.velocity_z;
138 old_speed = vlen(self.velocity);
139 old_dir = normalize(self.velocity);
141 //ggravity = (autocvar_sv_gravity / self.mass) * '0 0 100';
142 acceleration = (force / self.mass) * dir;
143 //acceleration -= old_dir * (old_speed / self.mass);
144 acceleration -= ggravity;
146 if(self.waterlevel > 1)
148 ffriction = self.water_friction;
149 acceleration += self.buoyancy * '0 0 1';
152 if(self.flags & FL_ONGROUND)
153 ffriction = self.ground_friction;
155 ffriction = self.air_friction;
157 acceleration *= ffriction;
158 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
159 self.velocity += acceleration * movelib_deltatime;
160 self.velocity_z = v_z;
166 void movelib_move_simple(vector newdir,float velo,float blendrate)
168 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
171 #define movelib_move_simple(newdir,velo,blendrate) \
172 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo
174 void movelib_beak_simple(float force)
180 mspeed = max(0,vlen(self.velocity) - force);
181 mdir = normalize(self.velocity);
182 vz = self.velocity_z;
183 self.velocity = mdir * mspeed;
184 self.velocity_z = vz;
188 Pitches and rolls the entity to match the gound.
189 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
193 void movelib_groundalign4point(float spring_length, float spring_up, float blendrate, float _max)
195 vector a, b, c, d, e, r, push_angle, ahead, side;
198 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
199 e = v_up * spring_length;
201 // Put springs slightly inside bbox
202 ahead = v_forward * (self.maxs_x * 0.8);
203 side = v_right * (self.maxs_y * 0.8);
205 a = r + ahead + side;
206 b = r + ahead - side;
207 c = r - ahead + side;
208 d = r - ahead - side;
210 traceline(a, a - e,MOVE_NORMAL,self);
211 a_z = (1 - trace_fraction);
214 traceline(b, b - e,MOVE_NORMAL,self);
215 b_z = (1 - trace_fraction);
218 traceline(c, c - e,MOVE_NORMAL,self);
219 c_z = (1 - trace_fraction);
222 traceline(d, d - e,MOVE_NORMAL,self);
223 d_z = (1 - trace_fraction);
230 push_angle_x = (a_z - c_z) * _max;
231 push_angle_x += (b_z - d_z) * _max;
233 push_angle_z = (b_z - a_z) * _max;
234 push_angle_z += (d_z - c_z) * _max;
236 //self.angles_x += push_angle_x * 0.95;
237 //self.angles_z += push_angle_z * 0.95;
239 self.angles_x = ((1-blendrate) * self.angles_x) + (push_angle_x * blendrate);
240 self.angles_z = ((1-blendrate) * self.angles_z) + (push_angle_z * blendrate);