]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/movelib.qc
Functions for easy access to steering, pathing and moving.
[divverent/nexuiz.git] / data / qcsrc / server / movelib.qc
1 .float mass;\r
2 \r
3 /**\r
4     Simulate drag\r
5     self.velocity = movelib_vdrag(self.velocity,0.02,0.5);\r
6 **/\r
7 vector movelib_drag(float drag, float exp)\r
8 {\r
9     float lspeed,ldrag;\r
10 \r
11     lspeed = vlen(self.velocity);\r
12     ldrag = lspeed * drag;\r
13     ldrag = ldrag * drag * exp;\r
14     ldrag = 1 - (ldrag / lspeed);\r
15 \r
16     return self.velocity * ldrag;\r
17 }\r
18 \r
19 /**\r
20     Simulate drag\r
21     self.velocity = movelib_vdrag(somespeed,0.01,0.7);\r
22 **/\r
23 float movelib_dragflt(float fspeed,float drag,float exp)\r
24 {\r
25     float ldrag;\r
26 \r
27     ldrag = fspeed * drag;\r
28     ldrag = ldrag * ldrag * exp;\r
29     ldrag = 1 - (ldrag / fspeed);\r
30 \r
31     return ldrag;\r
32 }\r
33 \r
34 /**\r
35     Do a inertia simulation based on velocity.\r
36     Basicaly, this allows you to simulate objects loss steering with speed.\r
37     self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);\r
38 **/\r
39 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)\r
40 {\r
41     float influense;\r
42 \r
43     influense = vlen(self.velocity) * (1 / vel_max);\r
44 \r
45     influense = bound(newmin,influense,oldmax);\r
46 \r
47     return (vel_new * (1 - influense)) + (self.velocity * influense);\r
48 }\r
49 \r
50 vector movelib_inertmove(vector new_vel,float new_bias)\r
51 {\r
52     return new_vel * new_bias + self.velocity * (1-new_bias);\r
53 }\r
54 \r
55 \r
56 /**\r
57     Applies absolute force to a velocity\r
58 **/\r
59 vector movelib_accelerate(vector vel,float force)\r
60 {\r
61     return normalize(vel) * (vlen(vel) + force);\r
62 }\r
63 vector movelib_decelerate(vector vel,float force)\r
64 {\r
65     return normalize(vel) * (vlen(vel) - force);\r
66 }\r
67 \r
68 vector movelib_velocity_transfer(entity source,entity destination)\r
69 {\r
70     return '0 0 0';\r
71 }\r