9 float trigger_push_calculatevelocity_flighttime;
11 void trigger_push_use()
14 self.team = activator.team;
18 trigger_push_calculatevelocity
21 org - origin of the object which is to be pushed
22 tgt - target entity (can be either a point or a model entity; if it is
23 the latter, its midpoint is used)
24 ht - jump height, measured from the higher one of org and tgt's midpoint
26 Returns: velocity for the jump
27 the global trigger_push_calculatevelocity_flighttime is set to the total
31 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
33 float grav, sdist, zdist, vs, vz, jumpheight;
36 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
38 grav = autocvar_sv_gravity;
40 zdist = torg_z - org_z;
41 sdist = vlen(torg - org - zdist * '0 0 1');
42 sdir = normalize(torg - org - zdist * '0 0 1');
44 // how high do we need to push the player?
45 jumpheight = fabs(ht);
47 jumpheight = jumpheight + zdist;
52 You will not understand the following equations anyway...
53 But here is what I did to get them.
58 z(t) = t * vz - 1/2 grav t^2
64 max(z, ti) = jumpheight
66 From these three equations, you will find the three parameters vs, vz
70 // push him so high...
71 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
73 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
79 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
80 // ALWAYS solvable because jumpheight >= zdist
82 solution_y = solution_x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0)
84 solution_x = solution_y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
91 // almost straight line type
92 // jump apex is before the jump
93 // we must take the larger one
94 trigger_push_calculatevelocity_flighttime = solution_y;
99 // jump apex is during the jump
100 // we must take the larger one too
101 trigger_push_calculatevelocity_flighttime = solution_y;
109 // almost straight line type
110 // jump apex is after the jump
111 // we must take the smaller one
112 trigger_push_calculatevelocity_flighttime = solution_x;
117 // jump apex is during the jump
118 // we must take the larger one
119 trigger_push_calculatevelocity_flighttime = solution_y;
122 vs = sdist / trigger_push_calculatevelocity_flighttime;
124 // finally calculate the velocity
125 return sdir * vs + '0 0 1' * vz;
128 void trigger_push_touch()
130 if (self.active == ACTIVE_NOT)
133 if (!isPushable(other))
137 if((self.spawnflags & 4 == 0) == (self.team != other.team))
144 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
149 RandomSelection_Init();
150 for(e = world; (e = find(e, targetname, self.target)); )
153 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
155 RandomSelection_Add(e, 0, string_null, 1, 1);
157 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
161 other.velocity = self.movedir;
164 other.flags &~= FL_ONGROUND;
166 if (other.classname == "player")
168 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
169 other.oldvelocity = other.velocity;
171 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
173 // flash when activated
174 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
175 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
176 self.pushltime = time + 0.2;
179 ct = clienttype(other);
180 if( ct == CLIENTTYPE_REAL || ct == CLIENTTYPE_BOT)
185 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
186 if(other.(jumppadsused[i]) == self)
190 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
191 other.jumppadcount = other.jumppadcount + 1;
194 if(ct == CLIENTTYPE_REAL)
197 centerprint(other, self.message);
200 other.lastteleporttime = time;
202 if (!other.animstate_override)
205 setanim(other, other.anim_duckjump, FALSE, TRUE, TRUE);
207 setanim(other, other.anim_jump, FALSE, TRUE, TRUE);
211 other.jumppadcount = TRUE;
213 // reset tracking of who pushed you into a hazard (for kill credit)
217 if(self.enemy.target)
227 if (other.flags & FL_PROJECTILE)
229 other.angles = vectoangles (other.velocity);
230 switch(other.movetype)
233 other.movetype = MOVETYPE_TOSS;
236 case MOVETYPE_BOUNCEMISSILE:
237 other.movetype = MOVETYPE_BOUNCE;
241 UpdateCSQCProjectile(other);
244 if (self.spawnflags & PUSH_ONCE)
246 self.touch = SUB_Null;
247 self.think = SUB_Remove;
248 self.nextthink = time;
253 void trigger_push_findtarget()
258 // first calculate a typical start point for the jump
259 org = (self.absmin + self.absmax) * 0.5;
260 org_z = self.absmax_z - PL_MIN_z;
266 for(t = world; (t = find(t, targetname, self.target)); )
271 setsize(e, PL_MIN, PL_MAX);
272 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
274 if(e.movetype == MOVETYPE_NONE)
275 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
282 objerror ("Jumppad with nonexistant target");
287 // exactly one dest - bots love that
288 self.enemy = find(e, targetname, self.target);
292 // have to use random selection every single time
300 setsize(e, PL_MIN, PL_MAX);
301 e.velocity = self.movedir;
303 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
311 * target: target of jump
312 * height: the absolute value is the height of the highest point of the jump
313 * trajectory above the higher one of the player and the target.
314 * the sign indicates whether the highest point is INSIDE (positive)
315 * or OUTSIDE (negative) of the jump trajectory. General rule: use
316 * positive values for targets mounted on the floor, and use negative
317 * values to target a point on the ceiling.
318 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
320 void spawnfunc_trigger_push()
326 self.active = ACTIVE_ACTIVE;
327 self.use = trigger_push_use;
328 self.touch = trigger_push_touch;
333 self.movedir = self.movedir * self.speed * 10;
336 self.noise = "misc/jumppad.wav";
337 precache_sound (self.noise);
339 // this must be called to spawn the teleport waypoints for bots
340 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
343 void spawnfunc_target_push() {}
344 void spawnfunc_info_notnull() {}
345 void spawnfunc_target_position() {}