10 float trigger_push_calculatevelocity_flighttime;
12 void trigger_push_use()
15 self.team = activator.team;
19 trigger_push_calculatevelocity
22 org - origin of the object which is to be pushed
23 tgt - target entity (can be either a point or a model entity; if it is
24 the latter, its midpoint is used)
25 ht - jump height, measured from the higher one of org and tgt's midpoint
27 Returns: velocity for the jump
28 the global trigger_push_calculatevelocity_flighttime is set to the total
32 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
34 float grav, sdist, zdist, vs, vz, jumpheight;
37 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
39 grav = autocvar_sv_gravity;
41 zdist = torg_z - org_z;
42 sdist = vlen(torg - org - zdist * '0 0 1');
43 sdir = normalize(torg - org - zdist * '0 0 1');
45 // how high do we need to push the player?
46 jumpheight = fabs(ht);
48 jumpheight = jumpheight + zdist;
53 You will not understand the following equations anyway...
54 But here is what I did to get them.
59 z(t) = t * vz - 1/2 grav t^2
65 max(z, ti) = jumpheight
67 From these three equations, you will find the three parameters vs, vz
71 // push him so high...
72 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
74 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
80 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
81 // ALWAYS solvable because jumpheight >= zdist
83 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)
85 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)
92 // almost straight line type
93 // jump apex is before the jump
94 // we must take the larger one
95 trigger_push_calculatevelocity_flighttime = solution_y;
100 // jump apex is during the jump
101 // we must take the larger one too
102 trigger_push_calculatevelocity_flighttime = solution_y;
110 // almost straight line type
111 // jump apex is after the jump
112 // we must take the smaller one
113 trigger_push_calculatevelocity_flighttime = solution_x;
118 // jump apex is during the jump
119 // we must take the larger one
120 trigger_push_calculatevelocity_flighttime = solution_y;
123 vs = sdist / trigger_push_calculatevelocity_flighttime;
125 // finally calculate the velocity
126 return sdir * vs + '0 0 1' * vz;
129 void trigger_push_touch()
131 if (self.active == ACTIVE_NOT)
134 if (!isPushable(other))
138 if((self.spawnflags & 4 == 0) == (self.team != other.team))
145 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
150 RandomSelection_Init();
151 for(e = world; (e = find(e, targetname, self.target)); )
154 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
156 RandomSelection_Add(e, 0, string_null, 1, 1);
158 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
162 other.velocity = self.movedir;
165 other.flags &~= FL_ONGROUND;
167 if (IS_PLAYER(other))
169 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
170 other.oldvelocity = other.velocity;
172 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
174 // flash when activated
175 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
176 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
177 self.pushltime = time + 0.2;
179 if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
184 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
185 if(other.(jumppadsused[i]) == self)
189 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
190 other.jumppadcount = other.jumppadcount + 1;
193 if(IS_REAL_CLIENT(other))
196 centerprint(other, self.message);
199 other.lastteleporttime = time;
201 if (other.deadflag == DEAD_NO)
202 animdecide_setaction(other, ANIMACTION_JUMP, TRUE);
205 other.jumppadcount = TRUE;
207 // reset tracking of who pushed you into a hazard (for kill credit)
209 other.istypefrag = 0;
212 if(self.enemy.target)
222 if (other.flags & FL_PROJECTILE)
224 other.angles = vectoangles (other.velocity);
225 switch(other.movetype)
228 other.movetype = MOVETYPE_TOSS;
231 case MOVETYPE_BOUNCEMISSILE:
232 other.movetype = MOVETYPE_BOUNCE;
236 UpdateCSQCProjectile(other);
239 if (self.spawnflags & PUSH_ONCE)
241 self.touch = func_null;
242 self.think = SUB_Remove;
243 self.nextthink = time;
248 void trigger_push_findtarget()
253 // first calculate a typical start point for the jump
254 org = (self.absmin + self.absmax) * 0.5;
255 org_z = self.absmax_z - PL_MIN_z;
261 for(t = world; (t = find(t, targetname, self.target)); )
266 setsize(e, PL_MIN, PL_MAX);
267 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
269 if(e.movetype == MOVETYPE_NONE)
270 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
277 objerror ("Jumppad with nonexistant target");
282 // exactly one dest - bots love that
283 self.enemy = find(world, targetname, self.target);
287 // have to use random selection every single time
295 setsize(e, PL_MIN, PL_MAX);
296 e.velocity = self.movedir;
298 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
306 * target: target of jump
307 * height: the absolute value is the height of the highest point of the jump
308 * trajectory above the higher one of the player and the target.
309 * the sign indicates whether the highest point is INSIDE (positive)
310 * or OUTSIDE (negative) of the jump trajectory. General rule: use
311 * positive values for targets mounted on the floor, and use negative
312 * values to target a point on the ceiling.
313 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
315 void spawnfunc_trigger_push()
321 self.active = ACTIVE_ACTIVE;
322 self.use = trigger_push_use;
323 self.touch = trigger_push_touch;
328 self.movedir = self.movedir * self.speed * 10;
331 self.noise = "misc/jumppad.wav";
332 precache_sound (self.noise);
334 // this must be called to spawn the teleport waypoints for bots
335 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
338 void spawnfunc_target_push() {}
339 void spawnfunc_info_notnull() {}
340 void spawnfunc_target_position() {}