5 self.velocity = movelib_dragvec(self.velocity,0.02,0.5);
7 vector movelib_dragvec(float drag, float exp_)
11 lspeed = vlen(self.velocity);
12 ldrag = lspeed * drag;
13 ldrag = ldrag * (drag * exp_);
14 ldrag = 1 - (ldrag / lspeed);
16 return self.velocity * ldrag;
21 self.velocity *= movelib_dragflt(somespeed,0.01,0.7);
23 float movelib_dragflt(float fspeed,float drag,float exp_)
27 ldrag = fspeed * drag;
28 ldrag = ldrag * ldrag * exp_;
29 ldrag = 1 - (ldrag / fspeed);
35 Do a inertia simulation based on velocity.
36 Basicaly, this allows you to simulate loss of steering with higher speed.
37 self.velocity = movelib_inertmove_byspeed(self.velocity,newvel,1000,0.1,0.9);
39 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
43 influense = vlen(self.velocity) * (1 / vel_max);
45 influense = bound(newmin,influense,oldmax);
47 return (vel_new * (1 - influense)) + (self.velocity * influense);
50 vector movelib_inertmove(vector new_vel,float new_bias)
52 return new_vel * new_bias + self.velocity * (1-new_bias);
55 .float movelib_lastupdate;
56 void movelib_move(vector force,float max_velocity,float drag,float theMass,float breakforce)
63 deltatime = time - self.movelib_lastupdate;
64 if (deltatime > 0.15) deltatime = 0;
65 self.movelib_lastupdate = time;
66 if (!deltatime) return;
68 mspeed = vlen(self.velocity);
71 acceleration = vlen(force) / theMass;
73 acceleration = vlen(force);
75 if (self.flags & FL_ONGROUND)
79 breakvec = (normalize(self.velocity) * (breakforce / theMass) * deltatime);
80 self.velocity = self.velocity - breakvec;
83 self.velocity = self.velocity + force * (acceleration * deltatime);
87 self.velocity = movelib_dragvec(drag, 1);
89 if (self.waterlevel > 1)
91 self.velocity = self.velocity + force * (acceleration * deltatime);
92 self.velocity = self.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
95 self.velocity = self.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
97 mspeed = vlen(self.velocity);
100 if (mspeed > max_velocity)
101 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
106 .float side_friction;
107 .float ground_friction;
109 .float water_friction;
111 float movelib_deltatime;
113 void movelib_startupdate()
115 movelib_deltatime = time - self.movelib_lastupdate;
117 if (movelib_deltatime > 0.5)
118 movelib_deltatime = 0;
120 self.movelib_lastupdate = time;
123 void movelib_update(vector dir,float force)
134 if(!movelib_deltatime)
136 v_z = self.velocity_z;
137 old_speed = vlen(self.velocity);
138 old_dir = normalize(self.velocity);
140 //ggravity = (autocvar_sv_gravity / self.mass) * '0 0 100';
141 acceleration = (force / self.mass) * dir;
142 //acceleration -= old_dir * (old_speed / self.mass);
143 acceleration -= ggravity;
145 if(self.waterlevel > 1)
147 ffriction = self.water_friction;
148 acceleration += self.buoyancy * '0 0 1';
151 if(self.flags & FL_ONGROUND)
152 ffriction = self.ground_friction;
154 ffriction = self.air_friction;
156 acceleration *= ffriction;
157 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
158 self.velocity += acceleration * movelib_deltatime;
159 self.velocity_z = v_z;
164 void movelib_move_simple(vector newdir,float velo,float blendrate)
166 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
169 void movelib_beak_simple(float force)
175 mspeed = max(0,vlen(self.velocity) - force);
176 mdir = normalize(self.velocity);
177 vz = self.velocity_z;
178 self.velocity = mdir * mspeed;
179 self.velocity_z = vz;
183 Pitches and rolls the entity to match the gound.
184 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
186 void movelib_groundalign4point(float spring_length, float spring_up, float blendrate)
188 vector a, b, c, d, e, r, push_angle, ahead, side;
191 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
192 e = v_up * spring_length;
194 // Put springs slightly inside bbox
195 ahead = v_forward * (self.maxs_x * 0.8);
196 side = v_right * (self.maxs_y * 0.8);
198 a = r + ahead + side;
199 b = r + ahead - side;
200 c = r - ahead + side;
201 d = r - ahead - side;
203 traceline(a, a - e,MOVE_NORMAL,self);
204 a_z = (1 - trace_fraction);
207 traceline(b, b - e,MOVE_NORMAL,self);
208 b_z = (1 - trace_fraction);
211 traceline(c, c - e,MOVE_NORMAL,self);
212 c_z = (1 - trace_fraction);
215 traceline(d, d - e,MOVE_NORMAL,self);
216 d_z = (1 - trace_fraction);
223 push_angle_x = (a_z - c_z) * 45;
224 push_angle_x += (b_z - d_z) * 45;
226 push_angle_z = (b_z - a_z) * 45;
227 push_angle_z += (d_z - c_z) * 45;
229 //self.angles_x += push_angle_x * 0.95;
230 //self.angles_z += push_angle_z * 0.95;
232 self.angles_x = ((1-blendrate) * self.angles_x) + (push_angle_x * blendrate);
233 self.angles_z = ((1-blendrate) * self.angles_z) + (push_angle_z * blendrate);