3 self.velocity = movelib_dragvec(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_dragflt(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 loss of steering with higher speed.
\r
35 self.velocity = movelib_inertmove_byspeed(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 theMass,float breakforce)
\r
61 deltatime = time - self.movelib_lastupdate;
\r
62 if (deltatime > 0.15) deltatime = 0;
\r
63 self.movelib_lastupdate = time;
\r
64 if (!deltatime) return;
\r
66 mspeed = vlen(self.velocity);
\r
69 acceleration = vlen(force) / theMass;
\r
71 acceleration = vlen(force);
\r
73 if (self.flags & FL_ONGROUND)
\r
77 breakvec = (normalize(self.velocity) * (breakforce / theMass) * deltatime);
\r
78 self.velocity = self.velocity - breakvec;
\r
81 self.velocity = self.velocity + force * (acceleration * deltatime);
\r
85 self.velocity = movelib_dragvec(drag, 1);
\r
87 if (self.waterlevel > 1)
\r
89 self.velocity = self.velocity + force * (acceleration * deltatime);
\r
90 self.velocity = self.velocity + '0 0 0.05' * sv_gravity * deltatime;
\r
93 self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;
\r
95 mspeed = vlen(self.velocity);
\r
98 if (mspeed > max_velocity)
\r
99 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
\r
104 .float side_friction;
\r
105 .float ground_friction;
\r
106 .float air_friction;
\r
107 .float water_friction;
\r
109 float movelib_deltatime;
\r
111 void movelib_startupdate()
\r
113 movelib_deltatime = time - self.movelib_lastupdate;
\r
115 if (movelib_deltatime > 0.5)
\r
116 movelib_deltatime = 0;
\r
118 self.movelib_lastupdate = time;
\r
121 void movelib_update(vector dir,float force)
\r
123 vector acceleration;
\r
125 float ffriction,v_z;
\r
132 if(!movelib_deltatime)
\r
134 v_z = self.velocity_z;
\r
135 old_speed = vlen(self.velocity);
\r
136 old_dir = normalize(self.velocity);
\r
138 //ggravity = (sv_gravity / self.mass) * '0 0 100';
\r
139 acceleration = (force / self.mass) * dir;
\r
140 //acceleration -= old_dir * (old_speed / self.mass);
\r
141 acceleration -= ggravity;
\r
143 if(self.waterlevel > 1)
\r
145 ffriction = self.water_friction;
\r
146 acceleration += self.buoyancy * '0 0 1';
\r
149 if(self.flags & FL_ONGROUND)
\r
150 ffriction = self.ground_friction;
\r
152 ffriction = self.air_friction;
\r
154 acceleration *= ffriction;
\r
155 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
\r
156 self.velocity += acceleration * movelib_deltatime;
\r
157 self.velocity_z = v_z;
\r
162 void movelib_move_simple(vector newdir,float velo,float blendrate)
\r
164 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
\r
167 void movelib_beak_simple(float force)
\r
173 mspeed = max(0,vlen(self.velocity) - force);
\r
174 mdir = normalize(self.velocity);
\r
175 vz = self.velocity_z;
\r
176 self.velocity = mdir * mspeed;
\r
177 self.velocity_z = vz;
\r
181 Pitches and rolls the entity to match the gound.
\r
182 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
\r
184 void movelib_groundalign4point(float spring_length, float spring_up, float blendrate)
\r
186 vector a, b, c, d, e, r, push_angle, ahead, side;
\r
189 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
\r
190 e = v_up * spring_length;
\r
192 // Put springs slightly inside bbox
\r
193 ahead = v_forward * (self.maxs_x * 0.8);
\r
194 side = v_right * (self.maxs_y * 0.8);
\r
196 a = r + ahead + side;
\r
197 b = r + ahead - side;
\r
198 c = r - ahead + side;
\r
199 d = r - ahead - side;
\r
201 traceline(a, a - e,MOVE_NORMAL,self);
\r
202 a_z = (1 - trace_fraction);
\r
205 traceline(b, b - e,MOVE_NORMAL,self);
\r
206 b_z = (1 - trace_fraction);
\r
209 traceline(c, c - e,MOVE_NORMAL,self);
\r
210 c_z = (1 - trace_fraction);
\r
213 traceline(d, d - e,MOVE_NORMAL,self);
\r
214 d_z = (1 - trace_fraction);
\r
221 push_angle_x = (a_z - c_z) * 45;
\r
222 push_angle_x += (b_z - d_z) * 45;
\r
224 push_angle_z = (b_z - a_z) * 45;
\r
225 push_angle_z += (d_z - c_z) * 45;
\r
227 //self.angles_x += push_angle_x * 0.95;
\r
228 //self.angles_z += push_angle_z * 0.95;
\r
230 self.angles_x = ((1-blendrate) * self.angles_x) + (push_angle_x * blendrate);
\r
231 self.angles_z = ((1-blendrate) * self.angles_z) + (push_angle_z * blendrate);
\r