3 self.velocity = movelib_vdrag(self.velocity,0.02,0.5);
5 vector movelib_dragvec(float drag, float exp)
9 lspeed = vlen(self.velocity);
10 ldrag = lspeed * drag;
11 ldrag = ldrag * (drag * exp);
12 ldrag = 1 - (ldrag / lspeed);
14 return self.velocity * ldrag;
19 self.velocity = movelib_vdrag(somespeed,0.01,0.7);
21 float movelib_dragflt(float fspeed,float drag,float exp)
25 ldrag = fspeed * drag;
26 ldrag = ldrag * ldrag * exp;
27 ldrag = 1 - (ldrag / fspeed);
33 Do a inertia simulation based on velocity.
34 Basicaly, this allows you to simulate loss of steering with higher speed.
35 self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);
37 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
41 influense = vlen(self.velocity) * (1 / vel_max);
43 influense = bound(newmin,influense,oldmax);
45 return (vel_new * (1 - influense)) + (self.velocity * influense);
48 vector movelib_inertmove(vector new_vel,float new_bias)
50 return new_vel * new_bias + self.velocity * (1-new_bias);
53 .float movelib_lastupdate;
54 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)
61 deltatime = time - self.movelib_lastupdate;
62 if (deltatime > 0.15) deltatime = 0;
63 self.movelib_lastupdate = time;
64 if(!deltatime) return;
66 mspeed = vlen(self.velocity);
69 acceleration = vlen(force) / mass;
71 acceleration = vlen(force);
73 if(self.flags & FL_ONGROUND)
77 breakvec = (normalize(self.velocity) * (breakforce / mass) * deltatime);
\r
78 self.velocity = self.velocity - breakvec;
81 self.velocity = self.velocity + force * (acceleration * deltatime);
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;
95 mspeed = vlen(self.velocity);
98 if(mspeed > max_velocity)
99 self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
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)
164 self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
166 void movelib_beak_simple(float force)
\r
171 mspeed = max(0,vlen(self.velocity) - force);
\r
172 mdir = normalize(self.velocity);
\r
173 self.velocity = mdir * mspeed;
\r
177 void movelib_groundalign4point(float spring_length,float spring_up)
\r
179 vector a,b,c,d,e,r,push_angle;
\r
181 r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
\r
182 e = v_up * spring_length;
\r
184 a = r + (v_forward * self.maxs_x) + (v_right * self.maxs_y);
\r
185 b = r + (v_forward * self.maxs_x) - (v_right * self.maxs_y);
\r
186 c = r - (v_forward * self.maxs_x) + (v_right * self.maxs_y);
\r
187 d = r - (v_forward * self.maxs_x) - (v_right * self.maxs_y);
\r
189 traceline(a, a - e,MOVE_NORMAL,self);
\r
190 a_z = (1 - trace_fraction);
\r
192 traceline(b, b - e,MOVE_NORMAL,self);
\r
193 b_z = (1 - trace_fraction);
\r
195 traceline(c, c - e,MOVE_NORMAL,self);
\r
196 c_z = (1 - trace_fraction);
\r
198 traceline(d, d - e,MOVE_NORMAL,self);
\r
199 d_z = (1 - trace_fraction);
\r
205 push_angle_x = (a_z - c_z) * 45;
\r
206 push_angle_x += (b_z - d_z) * 45;
\r
208 push_angle_z = (b_z - a_z) * 45;
\r
209 push_angle_z += (d_z - c_z) * 45;
\r
211 self.angles_x += push_angle_x * 0.95;
\r
212 self.angles_z += push_angle_z * 0.95;
\r