8 this.velocity = movelib_dragvec(this.velocity,0.02,0.5);
10 vector movelib_dragvec(entity this, float drag, float exp_)
14 lspeed = vlen(this.velocity);
15 ldrag = lspeed * drag;
16 ldrag = ldrag * (drag * exp_);
17 ldrag = 1 - (ldrag / lspeed);
19 return this.velocity * ldrag;
24 this.velocity *= movelib_dragflt(somespeed,0.01,0.7);
26 float movelib_dragflt(float fspeed,float drag,float exp_)
30 ldrag = fspeed * drag;
31 ldrag = ldrag * ldrag * exp_;
32 ldrag = 1 - (ldrag / fspeed);
38 Do a inertia simulation based on velocity.
39 Basicaly, this allows you to simulate loss of steering with higher speed.
40 this.velocity = movelib_inertmove_byspeed(this.velocity,newvel,1000,0.1,0.9);
42 vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max,float newmin,float oldmax)
46 influense = vlen(this.velocity) * (1 / vel_max);
48 influense = bound(newmin,influense,oldmax);
50 return (vel_new * (1 - influense)) + (this.velocity * influense);
53 vector movelib_inertmove(entity this, vector new_vel,float new_bias)
55 return new_vel * new_bias + this.velocity * (1-new_bias);
58 void movelib_move(entity this, vector force,float max_velocity,float drag,float theMass,float breakforce)
65 deltatime = time - this.movelib_lastupdate;
66 if (deltatime > 0.15) deltatime = 0;
67 this.movelib_lastupdate = time;
68 if (!deltatime) return;
70 mspeed = vlen(this.velocity);
73 acceleration = vlen(force) / theMass;
75 acceleration = vlen(force);
77 if (IS_ONGROUND(this))
81 breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime);
82 this.velocity = this.velocity - breakvec;
85 this.velocity = this.velocity + force * (acceleration * deltatime);
89 this.velocity = movelib_dragvec(this, drag, 1);
91 if (this.waterlevel > 1)
93 this.velocity = this.velocity + force * (acceleration * deltatime);
94 this.velocity = this.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
97 this.velocity = this.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
99 mspeed = vlen(this.velocity);
102 if (mspeed > max_velocity)
103 this.velocity = normalize(this.velocity) * (mspeed - 50);//* max_velocity;
108 .float side_friction;
109 .float ground_friction;
111 .float water_friction;
113 float movelib_deltatime;
115 void movelib_startupdate(entity this)
117 movelib_deltatime = time - this.movelib_lastupdate;
119 if (movelib_deltatime > 0.5)
120 movelib_deltatime = 0;
122 this.movelib_lastupdate = time;
125 void movelib_update(entity this, vector dir,float force)
136 if(!movelib_deltatime)
138 v_z = this.velocity_z;
139 old_speed = vlen(this.velocity);
140 old_dir = normalize(this.velocity);
142 //ggravity = (autocvar_sv_gravity / this.mass) * '0 0 100';
143 acceleration = (force / this.mass) * dir;
144 //acceleration -= old_dir * (old_speed / this.mass);
145 acceleration -= ggravity;
147 if(this.waterlevel > 1)
149 ffriction = this.water_friction;
150 acceleration += this.buoyancy * '0 0 1';
153 if(IS_ONGROUND(this))
154 ffriction = this.ground_friction;
156 ffriction = this.air_friction;
158 acceleration *= ffriction;
159 //this.velocity = this.velocity * (ffriction * movelib_deltatime);
160 this.velocity += acceleration * movelib_deltatime;
161 this.velocity_z = v_z;
166 void movelib_brake_simple(entity this, float force)
172 mspeed = max(0,vlen(this.velocity) - force);
173 mdir = normalize(this.velocity);
174 vz = this.velocity.z;
175 this.velocity = mdir * mspeed;
176 this.velocity_z = vz;
180 Pitches and rolls the entity to match the gound.
181 Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.
185 void movelib_groundalign4point(entity this, float spring_length, float spring_up, float blendrate, float _max)
187 vector a, b, c, d, e, r, push_angle, ahead, side;
190 r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up);
191 e = v_up * spring_length;
193 // Put springs slightly inside bbox
194 ahead = v_forward * (this.maxs.x * 0.8);
195 side = v_right * (this.maxs.y * 0.8);
197 a = r + ahead + side;
198 b = r + ahead - side;
199 c = r - ahead + side;
200 d = r - ahead - side;
202 traceline(a, a - e,MOVE_NORMAL,this);
203 a.z = (1 - trace_fraction);
206 traceline(b, b - e,MOVE_NORMAL,this);
207 b.z = (1 - trace_fraction);
210 traceline(c, c - e,MOVE_NORMAL,this);
211 c.z = (1 - trace_fraction);
214 traceline(d, d - e,MOVE_NORMAL,this);
215 d.z = (1 - trace_fraction);
222 push_angle.x = (a.z - c.z) * _max;
223 push_angle.x += (b.z - d.z) * _max;
225 push_angle.z = (b.z - a.z) * _max;
226 push_angle.z += (d.z - c.z) * _max;
228 //this.angles_x += push_angle_x * 0.95;
229 //this.angles_z += push_angle_z * 0.95;
231 this.angles_x = ((1-blendrate) * this.angles.x) + (push_angle.x * blendrate);
232 this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate);