Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
movelib.qc
Go to the documentation of this file.
1#include "movelib.qh"
2
3#ifdef SVQC
4.vector moveto;
5
10vector movelib_dragvec(entity this, float drag, float exp_)
11{
12 float lspeed,ldrag;
13
14 lspeed = vlen(this.velocity);
15 ldrag = lspeed * drag;
16 ldrag *= drag * exp_;
17 ldrag = 1 - (ldrag / lspeed);
18
19 return this.velocity * ldrag;
20}
21
26float movelib_dragflt(float fspeed,float drag,float exp_)
27{
28 float ldrag = fspeed * drag;
29 ldrag *= ldrag * exp_;
30 ldrag = 1 - (ldrag / fspeed);
31
32 return ldrag;
33}
34
40vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max,float newmin,float oldmax)
41{
42 float influense = vlen(this.velocity) * (1 / vel_max);
43
44 influense = bound(newmin,influense,oldmax);
45
46 return (vel_new * (1 - influense)) + (this.velocity * influense);
47}
48
49vector movelib_inertmove(entity this, vector new_vel,float new_bias)
50{
51 return new_vel * new_bias + this.velocity * (1-new_bias);
52}
53
54void movelib_move(entity this, vector force,float max_velocity,float drag,float theMass,float breakforce)
55{
56 float deltatime;
57 float acceleration;
58 float mspeed;
59 vector breakvec;
60
61 deltatime = time - this.movelib_lastupdate;
62 if (deltatime > 0.15) deltatime = 0;
63 this.movelib_lastupdate = time;
64 if (!deltatime) return;
65
66 mspeed = vlen(this.velocity);
67
68 if (theMass)
69 acceleration = vlen(force) / theMass;
70 else
71 acceleration = vlen(force);
72
73 if (IS_ONGROUND(this))
74 {
75 if (breakforce)
76 {
77 breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime);
78 this.velocity -= breakvec;
79 }
80
81 this.velocity += force * (acceleration * deltatime);
82 }
83
84 if (drag)
85 this.velocity = movelib_dragvec(this, drag, 1);
86
87 if (this.waterlevel > 1)
88 {
89 this.velocity += force * (acceleration * deltatime)
90 + '0 0 0.05' * PHYS_GRAVITY(NULL) * deltatime;
91 }
92 else
93 this.velocity -= '0 0 1' * PHYS_GRAVITY(NULL) * deltatime;
94
95 mspeed = vlen(this.velocity);
96
97 if (max_velocity)
98 if (mspeed > max_velocity)
99 this.velocity = normalize(this.velocity) * (mspeed - 50);//* max_velocity;
100}
101
102/*
103.float mass;
104.float side_friction;
105.float ground_friction;
106.float air_friction;
107.float water_friction;
108.float buoyancy;
109float movelib_deltatime;
110
111void movelib_startupdate(entity this)
112{
113 movelib_deltatime = time - this.movelib_lastupdate;
114
115 if (movelib_deltatime > 0.5)
116 movelib_deltatime = 0;
117
118 this.movelib_lastupdate = time;
119}
120
121void movelib_update(entity this, vector dir,float force)
122{
123 vector acceleration;
124 float old_speed;
125 float ffriction,v_z;
126
127 vector breakvec;
128 vector old_dir;
129 vector ggravity;
130 vector old;
131
132 if(!movelib_deltatime)
133 return;
134 v_z = this.velocity_z;
135 old_speed = vlen(this.velocity);
136 old_dir = normalize(this.velocity);
137
138 //ggravity = (PHYS_GRAVITY(NULL) / this.mass) * '0 0 100';
139 acceleration = (force / this.mass) * dir;
140 //acceleration -= old_dir * (old_speed / this.mass);
141 acceleration -= ggravity;
142
143 if(this.waterlevel > 1)
144 {
145 ffriction = this.water_friction;
146 acceleration += this.buoyancy * '0 0 1';
147 }
148 else
149 if(IS_ONGROUND(this))
150 ffriction = this.ground_friction;
151 else
152 ffriction = this.air_friction;
153
154 ffriction = bound(0, ffriction, 1);
155 acceleration *= ffriction;
156 //this.velocity *= ffriction * movelib_deltatime;
157 this.velocity += acceleration * movelib_deltatime;
158 this.velocity_z = v_z;
159
160}
161*/
162
163void movelib_brake_simple(entity this, float force)
164{
165 float mspeed;
166 vector mdir;
167 float vz;
168
169 mspeed = max(0,vlen(this.velocity) - force);
170 mdir = normalize(this.velocity);
171 vz = this.velocity.z;
172 this.velocity = mdir * mspeed;
173 this.velocity_z = vz;
174}
175
180#endif
181
182void movelib_groundalign4point(entity this, float spring_length, float spring_up, float blendrate, float _max)
183{
184 vector a, b, c, d, e, r, push_angle, ahead, side;
185
186 push_angle.y = 0;
187 r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up);
188 e = v_up * spring_length;
189
190 // Put springs slightly inside bbox
191 ahead = v_forward * (this.maxs.x * 0.8);
192 side = v_right * (this.maxs.y * 0.8);
193
194 a = r + ahead + side;
195 b = r + ahead - side;
196 c = r - ahead + side;
197 d = r - ahead - side;
198
199 traceline(a, a - e,MOVE_NORMAL,this);
200 a.z = (1 - trace_fraction);
201 r = trace_endpos;
202
203 traceline(b, b - e,MOVE_NORMAL,this);
204 b.z = (1 - trace_fraction);
205 r += trace_endpos;
206
207 traceline(c, c - e,MOVE_NORMAL,this);
208 c.z = (1 - trace_fraction);
209 r += trace_endpos;
210
211 traceline(d, d - e,MOVE_NORMAL,this);
212 d.z = (1 - trace_fraction);
213 r += trace_endpos;
214
215 a.x = r.z;
216 r = this.origin;
217
218 push_angle.x = (a.z - c.z) * _max;
219 push_angle.x += (b.z - d.z) * _max;
220
221 push_angle.z = (b.z - a.z) * _max;
222 push_angle.z += (d.z - c.z) * _max;
223
224 //this.angles_x += push_angle_x * 0.95;
225 //this.angles_z += push_angle_z * 0.95;
226
227 this.angles_x = ((1-blendrate) * this.angles.x) + (push_angle.x * blendrate);
228 this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate);
229
230 //a = this.origin;
231 setorigin(this, r);
232}
233
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float waterlevel
Definition player.qh:225
vector v_up
const float MOVE_NORMAL
vector velocity
float time
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
float bound(float min, float value, float max)
float vlen(vector v)
vector normalize(vector v)
float max(float f,...)
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
void movelib_groundalign4point(entity this, float spring_length, float spring_up, float blendrate, float _max)
Pitches and rolls the entity to match the gound.
Definition movelib.qc:182
void movelib_brake_simple(entity this, float force)
Definition movelib.qc:163
float movelib_dragflt(float fspeed, float drag, float exp_)
Simulate drag this.velocity *= movelib_dragflt(somespeed,0.01,0.7);.
Definition movelib.qc:26
vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max, float newmin, float oldmax)
Do a inertia simulation based on velocity.
Definition movelib.qc:40
void movelib_move(entity this, vector force, float max_velocity, float drag, float theMass, float breakforce)
Definition movelib.qc:54
vector movelib_inertmove(entity this, vector new_vel, float new_bias)
Definition movelib.qc:49
vector moveto
Definition movelib.qc:4
float movelib_lastupdate
Definition movelib.qh:27
#define PHYS_GRAVITY(s)
Definition movetypes.qh:53
#define IS_ONGROUND(s)
Definition movetypes.qh:16
#define NULL
Definition post.qh:14
vector
Definition self.qh:92