Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
movelib.qc File Reference
#include "movelib.qh"
Include dependency graph for movelib.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void movelib_brake_simple (entity this, float force)
float movelib_dragflt (float fspeed, float drag, float exp_)
 Simulate drag this.velocity *= movelib_dragflt(somespeed,0.01,0.7);.
vector movelib_dragvec (entity this, float drag, float exp_)
 Simulate drag this.velocity = movelib_dragvec(this.velocity,0.02,0.5);.
void movelib_groundalign4point (entity this, float spring_length, float spring_up, float blendrate, float _max)
 Pitches and rolls the entity to match the gound.
vector movelib_inertmove (entity this, vector new_vel, float new_bias)
vector movelib_inertmove_byspeed (entity this, vector vel_new, float vel_max, float newmin, float oldmax)
 Do a inertia simulation based on velocity.
void movelib_move (entity this, vector force, float max_velocity, float drag, float theMass, float breakforce)

Variables

vector moveto

Function Documentation

◆ movelib_brake_simple()

void movelib_brake_simple ( entity this,
float force )

Definition at line 167 of file movelib.qc.

168{
169 float mspeed;
170 vector mdir;
171 float vz;
172
173 mspeed = max(0,vlen(this.velocity) - force);
174 mdir = normalize(this.velocity);
175 vz = this.velocity.z;
176 this.velocity = mdir * mspeed;
177 this.velocity_z = vz;
178}
vector velocity
float vlen(vector v)
vector normalize(vector v)
float max(float f,...)
vector
Definition self.qh:92

References entity(), max(), normalize(), vector, velocity, and vlen().

Referenced by ewheel_move_enemy(), ewheel_move_idle(), Monster_Move(), Monster_Move_2D(), and spiderbot_frame().

◆ movelib_dragflt()

float movelib_dragflt ( float fspeed,
float drag,
float exp_ )

Simulate drag this.velocity *= movelib_dragflt(somespeed,0.01,0.7);.

Definition at line 26 of file movelib.qc.

27{
28 float ldrag;
29
30 ldrag = fspeed * drag;
31 ldrag = ldrag * ldrag * exp_;
32 ldrag = 1 - (ldrag / fspeed);
33
34 return ldrag;
35}

◆ movelib_dragvec()

vector movelib_dragvec ( entity this,
float drag,
float exp_ )

Simulate drag this.velocity = movelib_dragvec(this.velocity,0.02,0.5);.

Definition at line 10 of file movelib.qc.

11{
12 float lspeed,ldrag;
13
14 lspeed = vlen(this.velocity);
15 ldrag = lspeed * drag;
16 ldrag = ldrag * (drag * exp_);
17 ldrag = 1 - (ldrag / lspeed);
18
19 return this.velocity * ldrag;
20}

References entity(), vector, velocity, and vlen().

Referenced by movelib_move().

◆ movelib_groundalign4point()

void movelib_groundalign4point ( entity this,
float spring_length,
float spring_up,
float blendrate,
float _max )

Pitches and rolls the entity to match the gound.

Yed need to set v_up and v_forward (generally by calling makevectors) before calling this.

Definition at line 186 of file movelib.qc.

187{
188 vector a, b, c, d, e, r, push_angle, ahead, side;
189
190 push_angle.y = 0;
191 r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up);
192 e = v_up * spring_length;
193
194 // Put springs slightly inside bbox
195 ahead = v_forward * (this.maxs.x * 0.8);
196 side = v_right * (this.maxs.y * 0.8);
197
198 a = r + ahead + side;
199 b = r + ahead - side;
200 c = r - ahead + side;
201 d = r - ahead - side;
202
203 traceline(a, a - e,MOVE_NORMAL,this);
204 a.z = (1 - trace_fraction);
205 r = trace_endpos;
206
207 traceline(b, b - e,MOVE_NORMAL,this);
208 b.z = (1 - trace_fraction);
209 r += trace_endpos;
210
211 traceline(c, c - e,MOVE_NORMAL,this);
212 c.z = (1 - trace_fraction);
213 r += trace_endpos;
214
215 traceline(d, d - e,MOVE_NORMAL,this);
216 d.z = (1 - trace_fraction);
217 r += trace_endpos;
218
219 a.x = r.z;
220 r = this.origin;
221 r.z = r.z;
222
223 push_angle.x = (a.z - c.z) * _max;
224 push_angle.x += (b.z - d.z) * _max;
225
226 push_angle.z = (b.z - a.z) * _max;
227 push_angle.z += (d.z - c.z) * _max;
228
229 //this.angles_x += push_angle_x * 0.95;
230 //this.angles_z += push_angle_z * 0.95;
231
232 this.angles_x = ((1-blendrate) * this.angles.x) + (push_angle.x * blendrate);
233 this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate);
234
235 //a = this.origin;
236 setorigin(this, r);
237}
vector v_up
const float MOVE_NORMAL
vector v_right
vector trace_endpos
vector maxs
vector absmax
vector v_forward
vector origin
float trace_fraction
vector absmin
ent angles
Definition ent_cs.qc:121

References absmax, absmin, angles, entity(), maxs, MOVE_NORMAL, origin, trace_endpos, trace_fraction, v_forward, v_right, v_up, and vector.

Referenced by spiderbot_frame(), and walker_draw().

◆ movelib_inertmove()

vector movelib_inertmove ( entity this,
vector new_vel,
float new_bias )

Definition at line 53 of file movelib.qc.

54{
55 return new_vel * new_bias + this.velocity * (1-new_bias);
56}

References entity(), vector, and velocity.

◆ movelib_inertmove_byspeed()

vector movelib_inertmove_byspeed ( entity this,
vector vel_new,
float vel_max,
float newmin,
float oldmax )

Do a inertia simulation based on velocity.

Basicaly, this allows you to simulate loss of steering with higher speed. this.velocity = movelib_inertmove_byspeed(this.velocity,newvel,1000,0.1,0.9);

Definition at line 42 of file movelib.qc.

43{
44 float influense;
45
46 influense = vlen(this.velocity) * (1 / vel_max);
47
48 influense = bound(newmin,influense,oldmax);
49
50 return (vel_new * (1 - influense)) + (this.velocity * influense);
51}
float bound(float min, float value, float max)

References bound(), entity(), vector, velocity, and vlen().

◆ movelib_move()

void movelib_move ( entity this,
vector force,
float max_velocity,
float drag,
float theMass,
float breakforce )

Definition at line 58 of file movelib.qc.

59{
60 float deltatime;
61 float acceleration;
62 float mspeed;
63 vector breakvec;
64
65 deltatime = time - this.movelib_lastupdate;
66 if (deltatime > 0.15) deltatime = 0;
67 this.movelib_lastupdate = time;
68 if (!deltatime) return;
69
70 mspeed = vlen(this.velocity);
71
72 if (theMass)
73 acceleration = vlen(force) / theMass;
74 else
75 acceleration = vlen(force);
76
77 if (IS_ONGROUND(this))
78 {
79 if (breakforce)
80 {
81 breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime);
82 this.velocity = this.velocity - breakvec;
83 }
84
85 this.velocity = this.velocity + force * (acceleration * deltatime);
86 }
87
88 if (drag)
89 this.velocity = movelib_dragvec(this, drag, 1);
90
91 if (this.waterlevel > 1)
92 {
93 this.velocity = this.velocity + force * (acceleration * deltatime);
94 this.velocity = this.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime;
95 }
96 else
97 this.velocity = this.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime;
98
99 mspeed = vlen(this.velocity);
100
101 if (max_velocity)
102 if (mspeed > max_velocity)
103 this.velocity = normalize(this.velocity) * (mspeed - 50);//* max_velocity;
104}
float waterlevel
Definition player.qh:226
#define autocvar_sv_gravity
Definition stats.qh:421
float time
vector movelib_dragvec(entity this, float drag, float exp_)
Simulate drag this.velocity = movelib_dragvec(this.velocity,0.02,0.5);.
Definition movelib.qc:10
float movelib_lastupdate
Definition movelib.qh:27
#define IS_ONGROUND(s)
Definition movetypes.qh:16

References autocvar_sv_gravity, entity(), IS_ONGROUND, movelib_dragvec(), movelib_lastupdate, normalize(), time, vector, velocity, vlen(), and waterlevel.

Variable Documentation

◆ moveto

vector moveto

Definition at line 4 of file movelib.qc.