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 (other.classname == "player")
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;
180 ct = clienttype(other);
181 if( ct == CLIENTTYPE_REAL || ct == CLIENTTYPE_BOT)
186 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
187 if(other.(jumppadsused[i]) == self)
191 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
192 other.jumppadcount = other.jumppadcount + 1;
195 if(ct == CLIENTTYPE_REAL)
198 centerprint(other, self.message);
201 other.lastteleporttime = time;
203 if (!other.animstate_override)
204 if (other.deadflag == DEAD_NO)
207 setanim(other, other.anim_duckjump, FALSE, TRUE, TRUE);
209 setanim(other, other.anim_jump, FALSE, TRUE, TRUE);
213 other.jumppadcount = TRUE;
215 // reset tracking of who pushed you into a hazard (for kill credit)
217 other.istypefrag = 0;
220 if(self.enemy.target)
230 if (other.flags & FL_PROJECTILE)
232 other.angles = vectoangles (other.velocity);
233 switch(other.movetype)
236 other.movetype = MOVETYPE_TOSS;
239 case MOVETYPE_BOUNCEMISSILE:
240 other.movetype = MOVETYPE_BOUNCE;
244 UpdateCSQCProjectile(other);
247 if (self.spawnflags & PUSH_ONCE)
249 self.touch = func_null;
250 self.think = SUB_Remove;
251 self.nextthink = time;
256 void trigger_push_findtarget()
261 // first calculate a typical start point for the jump
262 org = (self.absmin + self.absmax) * 0.5;
263 org_z = self.absmax_z - PL_MIN_z;
269 for(t = world; (t = find(t, targetname, self.target)); )
274 setsize(e, PL_MIN, PL_MAX);
275 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
277 if(e.movetype == MOVETYPE_NONE)
278 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
285 objerror ("Jumppad with nonexistant target");
290 // exactly one dest - bots love that
291 self.enemy = find(world, targetname, self.target);
295 // have to use random selection every single time
303 setsize(e, PL_MIN, PL_MAX);
304 e.velocity = self.movedir;
306 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
314 * target: target of jump
315 * height: the absolute value is the height of the highest point of the jump
316 * trajectory above the higher one of the player and the target.
317 * the sign indicates whether the highest point is INSIDE (positive)
318 * or OUTSIDE (negative) of the jump trajectory. General rule: use
319 * positive values for targets mounted on the floor, and use negative
320 * values to target a point on the ceiling.
321 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
323 void spawnfunc_trigger_push()
329 self.active = ACTIVE_ACTIVE;
330 self.use = trigger_push_use;
331 self.touch = trigger_push_touch;
336 self.movedir = self.movedir * self.speed * 10;
339 self.noise = "misc/jumppad.wav";
340 precache_sound (self.noise);
342 // this must be called to spawn the teleport waypoints for bots
343 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
346 void spawnfunc_target_push() {}
347 void spawnfunc_info_notnull() {}
348 void spawnfunc_target_position() {}