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