]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/movelib.qc
weapon system: fix "" errors
[divverent/nexuiz.git] / data / qcsrc / server / movelib.qc
1 /**
2     Simulate drag
3     self.velocity = movelib_vdrag(self.velocity,0.02,0.5);
4 **/
5 vector movelib_dragvec(float drag, float exp)
6 {
7     float lspeed,ldrag;
8
9     lspeed = vlen(self.velocity);
10     ldrag = lspeed * drag;
11     ldrag = ldrag * (drag * exp);
12     ldrag = 1 - (ldrag / lspeed);
13
14     return self.velocity * ldrag;
15 }
16
17 /**
18     Simulate drag
19     self.velocity = movelib_vdrag(somespeed,0.01,0.7);
20 **/
21 float movelib_dragflt(float fspeed,float drag,float exp)
22 {
23     float ldrag;
24
25     ldrag = fspeed * drag;
26     ldrag = ldrag * ldrag * exp;
27     ldrag = 1 - (ldrag / fspeed);
28
29     return ldrag;
30 }
31
32 /**
33     Do a inertia simulation based on velocity.
34     Basicaly, this allows you to simulate objects loss steering with speed.
35     self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);
36 **/
37 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
38 {
39     float influense;
40
41     influense = vlen(self.velocity) * (1 / vel_max);
42
43     influense = bound(newmin,influense,oldmax);
44
45     return (vel_new * (1 - influense)) + (self.velocity * influense);
46 }
47
48 vector movelib_inertmove(vector new_vel,float new_bias)
49 {
50     return new_vel * new_bias + self.velocity * (1-new_bias);
51 }
52
53 .float  movelib_lastupdate;
54 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)
55 {
56     float deltatime;
57     float acceleration;
58     //float mspeed;
59
60     deltatime = time - self.movelib_lastupdate;
61     if (deltatime > 0.15) deltatime = 0;
62     self.movelib_lastupdate = time;
63     if(!deltatime) return;
64
65     //mspeed = vlen(self.velocity);
66
67     if(mass)
68         acceleration = vlen(force) / mass;
69     else
70         acceleration = vlen(force);
71
72     if(self.flags & FL_ONGROUND)
73     {
74         if(breakforce)
75         {
76             breakforce = 1 - ((breakforce / mass) * deltatime);
77             self.velocity = self.velocity * breakforce;
78         }
79
80         self.velocity = self.velocity + force * (acceleration * deltatime);
81     }
82
83     self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;
84
85     if(drag)
86         self.velocity = movelib_dragvec(drag, 1);
87
88     if(max_velocity)
89     if(vlen(self.velocity) > max_velocity)
90         self.velocity = normalize(self.velocity) * max_velocity;
91 }
92
93 void movelib_move_simple(vector newdir,float velo,float turnrate)
94 {
95     vector olddir;
96
97     olddir = normalize(self.velocity);
98
99     self.velocity = normalize(olddir + newdir * turnrate) * velo;
100 }
101
102 /*
103 vector movelib_accelerate(float force)
104 {
105     vector vel;
106     vel = self.velocity;
107     vel = normalize(vel) * (vlen(vel) + force);
108     self.velocity = self.velocity  + vel;
109 }
110
111
112 vector movelib_decelerate(float force,float mass)
113 {
114     vector vel;
115     float decel;
116
117     if(mass)
118         decel = force / mass;
119     else
120         decel = force;
121
122     vel = self.velocity;
123     vel = normalize(vel) * max((vlen(vel) - decel),0);
124     self.velocity = self.velocity - vel;
125
126     if(vlen(self.velocity) < 5) self.velocity = '0 0 0';
127 }
128 */
129 vector movelib_velocity_transfer(entity source,entity destination)
130 {
131     return '0 0 0';
132 }