]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/movelib.qc
laser projectile delay (STUUUUUPID)
[divverent/nexuiz.git] / data / qcsrc / server / movelib.qc
1 .vector moveto;
2
3 /**
4     Simulate drag
5     self.velocity = movelib_vdrag(self.velocity,0.02,0.5);
6 **/
7 vector movelib_dragvec(float drag, float exp)
8 {
9     float lspeed,ldrag;
10
11     lspeed = vlen(self.velocity);
12     ldrag = lspeed * drag;
13     ldrag = ldrag * (drag * exp);
14     ldrag = 1 - (ldrag / lspeed);
15
16     return self.velocity * ldrag;
17 }
18
19 /**
20     Simulate drag
21     self.velocity = movelib_vdrag(somespeed,0.01,0.7);
22 **/
23 float movelib_dragflt(float fspeed,float drag,float exp)
24 {
25     float ldrag;
26
27     ldrag = fspeed * drag;
28     ldrag = ldrag * ldrag * exp;
29     ldrag = 1 - (ldrag / fspeed);
30
31     return ldrag;
32 }
33
34 /**
35     Do a inertia simulation based on velocity.
36     Basicaly, this allows you to simulate loss of steering with higher speed.
37     self.velocity = movelib_inertia_fromspeed(self.velocity,newvel,1000,0.1,0.9);
38 **/
39 vector movelib_inertmove_byspeed(vector vel_new, float vel_max,float newmin,float oldmax)
40 {
41     float influense;
42
43     influense = vlen(self.velocity) * (1 / vel_max);
44
45     influense = bound(newmin,influense,oldmax);
46
47     return (vel_new * (1 - influense)) + (self.velocity * influense);
48 }
49
50 vector movelib_inertmove(vector new_vel,float new_bias)
51 {
52     return new_vel * new_bias + self.velocity * (1-new_bias);
53 }
54
55 .float  movelib_lastupdate;
56 void movelib_move(vector force,float max_velocity,float drag,float mass,float breakforce)
57 {
58     float deltatime;
59     float acceleration;
60     float mspeed;
61     vector breakvec;
62
63     deltatime = time - self.movelib_lastupdate;
64     if (deltatime > 0.15) deltatime = 0;
65     self.movelib_lastupdate = time;
66     if (!deltatime) return;
67
68     mspeed = vlen(self.velocity);
69
70     if (mass)
71         acceleration = vlen(force) / mass;
72     else
73         acceleration = vlen(force);
74
75     if (self.flags & FL_ONGROUND)
76     {
77         if (breakforce)
78         {
79             breakvec = (normalize(self.velocity) * (breakforce / mass) * deltatime);
80             self.velocity = self.velocity - breakvec;
81         }
82
83         self.velocity = self.velocity + force * (acceleration * deltatime);
84     }
85
86     if (drag)
87         self.velocity = movelib_dragvec(drag, 1);
88
89     if (self.waterlevel > 1)
90     {
91         self.velocity = self.velocity + force * (acceleration * deltatime);
92         self.velocity = self.velocity + '0 0 0.05' * sv_gravity * deltatime;
93     }
94     else
95         self.velocity = self.velocity + '0 0 -1' * sv_gravity * deltatime;
96
97     mspeed = vlen(self.velocity);
98
99     if (max_velocity)
100         if (mspeed > max_velocity)
101             self.velocity = normalize(self.velocity) * (mspeed - 50);//* max_velocity;
102 }
103
104 /*
105 .float mass;
106 .float side_friction;
107 .float ground_friction;
108 .float air_friction;
109 .float water_friction;
110 .float buoyancy;
111 float movelib_deltatime;
112
113 void movelib_startupdate()
114 {
115     movelib_deltatime = time - self.movelib_lastupdate;
116
117     if (movelib_deltatime > 0.5)
118         movelib_deltatime = 0;
119
120     self.movelib_lastupdate = time;
121 }
122
123 void movelib_update(vector dir,float force)
124 {
125     vector acceleration;
126     float old_speed;
127     float ffriction,v_z;
128
129     vector breakvec;
130     vector old_dir;
131     vector ggravity;
132     vector old;
133
134     if(!movelib_deltatime)
135         return;
136     v_z = self.velocity_z;
137     old_speed    = vlen(self.velocity);
138     old_dir      = normalize(self.velocity);
139
140     //ggravity      =  (sv_gravity / self.mass) * '0 0 100';
141     acceleration =  (force / self.mass) * dir;
142     //acceleration -= old_dir * (old_speed / self.mass);
143     acceleration -= ggravity;
144
145     if(self.waterlevel > 1)
146     {
147         ffriction = self.water_friction;
148         acceleration += self.buoyancy * '0 0 1';
149     }
150     else
151         if(self.flags & FL_ONGROUND)
152             ffriction = self.ground_friction;
153         else
154             ffriction = self.air_friction;
155
156     acceleration *= ffriction;
157     //self.velocity = self.velocity * (ffriction * movelib_deltatime);
158     self.velocity += acceleration * movelib_deltatime;
159     self.velocity_z = v_z;
160
161 }
162 */
163
164 void movelib_move_simple(vector newdir,float velo,float blendrate)
165 {
166     self.velocity = self.velocity * (1 - blendrate) + (newdir * blendrate) * velo;
167 }
168 void movelib_beak_simple(float force)
169 {
170     float mspeed;
171     vector mdir;
172     float vz;
173
174     mspeed = max(0,vlen(self.velocity) - force);
175     mdir   = normalize(self.velocity);
176     vz = self.velocity_z;
177     self.velocity = mdir * mspeed;
178     self.velocity_z = vz;
179 }
180
181
182 void movelib_groundalign4point(float spring_length,float spring_up,float blendrate)
183 {
184     vector a,b,c,d,e,r,push_angle, ahead,side;
185
186     push_angle_y = 0;
187     r = (self.absmax + self.absmin) * 0.5 + (v_up * spring_up);
188     e = v_up * spring_length;
189
190     // Put springs slightly inside bbox
191     ahead = v_forward * (self.maxs_x * 0.85);
192     side  = v_right   * (self.maxs_y * 0.85);
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,self);
200     a_z =  (1 - trace_fraction);
201     r = trace_endpos;
202
203     traceline(b, b - e,MOVE_NORMAL,self);
204     b_z =  (1 - trace_fraction);
205     r += trace_endpos;
206
207     traceline(c, c - e,MOVE_NORMAL,self);
208     c_z =  (1 - trace_fraction);
209     r += trace_endpos;
210
211     traceline(d, d - e,MOVE_NORMAL,self);
212     d_z =  (1 - trace_fraction);
213     r += trace_endpos;
214
215     a_x = r_z;
216     r = self.origin;
217     r_z = r_z;
218
219     push_angle_x = (a_z - c_z) * 45;
220     push_angle_x += (b_z - d_z) * 45;
221
222     push_angle_z = (b_z - a_z) * 45;
223     push_angle_z += (d_z - c_z) * 45;
224
225     //self.angles_x += push_angle_x * 0.95;
226     //self.angles_z += push_angle_z * 0.95;
227
228     self.angles_x = ((1-blendrate) *  self.angles_x)  + (push_angle_x * blendrate);
229     self.angles_z = ((1-blendrate) *  self.angles_z)  + (push_angle_z * blendrate);
230
231     //a = self.origin;
232     setorigin(self,r);
233 }
234