5 self.velocity = movelib_vdrag(self.velocity,0.02,0.5);
\r
7 vector movelib_dragvec(float drag, float exp)
\r
11 lspeed = vlen(self.velocity);
\r
12 ldrag = lspeed * drag;
\r
13 ldrag = ldrag * (drag * exp);
\r
14 ldrag = 1 - (ldrag / lspeed);
\r
16 return self.velocity * ldrag;
\r
21 self.velocity = movelib_vdrag(somespeed,0.01,0.7);
\r
23 float movelib_dragflt(float fspeed,float drag,float exp)
\r
27 ldrag = fspeed * drag;
\r
28 ldrag = ldrag * ldrag * exp;
\r
29 ldrag = 1 - (ldrag / fspeed);
\r
35 Do a inertia simulation based on velocity.
\r
36 Basicaly, this allows you to simulate loss of steering with higher speed.
\r
37 self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);
\r
39 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
\r
43 influense = vlen(self.velocity) * (1 / vel_max);
\r
45 influense = bound(newmin,influense,oldmax);
\r
47 return (vel_new * (1 - influense)) + (self.velocity * influense);
\r
50 vector movelib_inertmove(vector new_vel,float new_bias)
\r
52 return new_vel * new_bias + self.velocity * (1-new_bias);
\r
55 .float movelib_lastupdate;
\r
56 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)
\r
63 deltatime = time - self.movelib_lastupdate;
\r
64 if (deltatime > 0.15) deltatime = 0;
\r
65 self.movelib_lastupdate = time;
\r
66 if (!deltatime) return;
\r
68 mspeed = vlen(self.velocity);
\r
71 acceleration = vlen(force) / mass;
\r
73 acceleration = vlen(force);
\r
75 if (self.flags & FL_ONGROUND)
\r
79 breakvec = (normalize(self.velocity) * (breakforce / mass) * deltatime);
\r
80 self.velocity = self.velocity - breakvec;
\r
83 self.velocity = self.velocity + force * (acceleration * deltatime);
\r
87 self.velocity = movelib_dragvec(drag, 1);
\r
89 if (self.waterlevel > 1)
\r
91 self.velocity = self.velocity + force * (acceleration * deltatime);
\r
92 self.velocity = self.velocity + '0 0 0.05' * sv_gravity * deltatime;
\r
95 self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;
\r
97 mspeed = vlen(self.velocity);
\r
100 if (mspeed > max_velocity)
\r
101 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
\r
106 .float side_friction;
\r
107 .float ground_friction;
\r
108 .float air_friction;
\r
109 .float water_friction;
\r
111 float movelib_deltatime;
\r
113 void movelib_startupdate()
\r
115 movelib_deltatime = time - self.movelib_lastupdate;
\r
117 if (movelib_deltatime > 0.5)
\r
118 movelib_deltatime = 0;
\r
120 self.movelib_lastupdate = time;
\r
123 void movelib_update(vector dir,float force)
\r
125 vector acceleration;
\r
127 float ffriction,v_z;
\r
134 if(!movelib_deltatime)
\r
136 v_z = self.velocity_z;
\r
137 old_speed = vlen(self.velocity);
\r
138 old_dir = normalize(self.velocity);
\r
140 //ggravity = (sv_gravity / self.mass) * '0 0 100';
\r
141 acceleration = (force / self.mass) * dir;
\r
142 //acceleration -= old_dir * (old_speed / self.mass);
\r
143 acceleration -= ggravity;
\r
145 if(self.waterlevel > 1)
\r
147 ffriction = self.water_friction;
\r
148 acceleration += self.buoyancy * '0 0 1';
\r
151 if(self.flags & FL_ONGROUND)
\r
152 ffriction = self.ground_friction;
\r
154 ffriction = self.air_friction;
\r
156 acceleration *= ffriction;
\r
157 //self.velocity = self.velocity * (ffriction * movelib_deltatime);
\r
158 self.velocity += acceleration * movelib_deltatime;
\r
159 self.velocity_z = v_z;
\r
164 void movelib_move_simple(vector newdir,float velo,float blendrate)
\r
166 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
\r
168 void movelib_beak_simple(float force)
\r
173 mspeed = max(0,vlen(self.velocity) - force);
\r
174 mdir = normalize(self.velocity);
\r
175 self.velocity = mdir * mspeed;
\r
179 void movelib_groundalign4point(float spring_length,float spring_up)
\r
181 vector a,b,c,d,e,r,push_angle, ahead,side;
\r
184 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
\r
185 e = v_up * spring_length;
\r
187 // Put springs slightly inside bbox
\r
188 ahead = v_forward * (self.maxs_x * 0.85);
\r
189 side = v_right * (self.maxs_y * 0.85);
\r
191 a = r + ahead + side;
\r
192 b = r + ahead - side;
\r
193 c = r - ahead + side;
\r
194 d = r - ahead - side;
\r
196 traceline(a, a - e,MOVE_NORMAL,self);
\r
197 a_z = (1 - trace_fraction);
\r
200 traceline(b, b - e,MOVE_NORMAL,self);
\r
201 b_z = (1 - trace_fraction);
\r
204 traceline(c, c - e,MOVE_NORMAL,self);
\r
205 c_z = (1 - trace_fraction);
\r
208 traceline(d, d - e,MOVE_NORMAL,self);
\r
209 d_z = (1 - trace_fraction);
\r
216 push_angle_x = (a_z - c_z) * 45;
\r
217 push_angle_x += (b_z - d_z) * 45;
\r
219 push_angle_z = (b_z - a_z) * 45;
\r
220 push_angle_z += (d_z - c_z) * 45;
\r
222 self.angles_x += push_angle_x * 0.95;
\r
223 self.angles_z += push_angle_z * 0.95;
\r