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 grav *= other.gravity;
43 zdist = torg_z - org_z;
44 sdist = vlen(torg - org - zdist * '0 0 1');
45 sdir = normalize(torg - org - zdist * '0 0 1');
47 // how high do we need to push the player?
48 jumpheight = fabs(ht);
50 jumpheight = jumpheight + zdist;
55 You will not understand the following equations anyway...
56 But here is what I did to get them.
61 z(t) = t * vz - 1/2 grav t^2
67 max(z, ti) = jumpheight
69 From these three equations, you will find the three parameters vs, vz
73 // push him so high...
74 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
76 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
82 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
83 // ALWAYS solvable because jumpheight >= zdist
85 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)
87 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)
94 // almost straight line type
95 // jump apex is before the jump
96 // we must take the larger one
97 trigger_push_calculatevelocity_flighttime = solution_y;
102 // jump apex is during the jump
103 // we must take the larger one too
104 trigger_push_calculatevelocity_flighttime = solution_y;
112 // almost straight line type
113 // jump apex is after the jump
114 // we must take the smaller one
115 trigger_push_calculatevelocity_flighttime = solution_x;
120 // jump apex is during the jump
121 // we must take the larger one
122 trigger_push_calculatevelocity_flighttime = solution_y;
125 vs = sdist / trigger_push_calculatevelocity_flighttime;
127 // finally calculate the velocity
128 return sdir * vs + '0 0 1' * vz;
131 void trigger_push_touch()
133 if (self.active == ACTIVE_NOT)
136 if (!isPushable(other))
140 if((self.spawnflags & 4 == 0) == (self.team != other.team))
147 other.velocity = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
152 RandomSelection_Init();
153 for(e = world; (e = find(e, targetname, self.target)); )
156 RandomSelection_Add(e, 0, string_null, e.cnt, 1);
158 RandomSelection_Add(e, 0, string_null, 1, 1);
160 other.velocity = trigger_push_calculatevelocity(other.origin, RandomSelection_chosen_ent, self.height);
164 other.velocity = self.movedir;
167 other.flags &~= FL_ONGROUND;
169 if (other.classname == "player")
171 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
172 other.oldvelocity = other.velocity;
174 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
176 // flash when activated
177 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
178 sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
179 self.pushltime = time + 0.2;
182 ct = clienttype(other);
183 if( ct == CLIENTTYPE_REAL || ct == CLIENTTYPE_BOT)
188 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
189 if(other.(jumppadsused[i]) == self)
193 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
194 other.jumppadcount = other.jumppadcount + 1;
197 if(ct == CLIENTTYPE_REAL)
200 centerprint(other, self.message);
203 other.lastteleporttime = time;
205 if (other.deadflag == DEAD_NO)
206 animdecide_setaction(other, ANIMACTION_JUMP, TRUE);
209 other.jumppadcount = TRUE;
211 // reset tracking of who pushed you into a hazard (for kill credit)
213 other.istypefrag = 0;
216 if(self.enemy.target)
226 if (other.flags & FL_PROJECTILE)
228 other.angles = vectoangles (other.velocity);
229 switch(other.movetype)
232 other.movetype = MOVETYPE_TOSS;
235 case MOVETYPE_BOUNCEMISSILE:
236 other.movetype = MOVETYPE_BOUNCE;
240 UpdateCSQCProjectile(other);
243 if (self.spawnflags & PUSH_ONCE)
245 self.touch = func_null;
246 self.think = SUB_Remove;
247 self.nextthink = time;
252 void trigger_push_findtarget()
257 // first calculate a typical start point for the jump
258 org = (self.absmin + self.absmax) * 0.5;
259 org_z = self.absmax_z - PL_MIN_z;
265 for(t = world; (t = find(t, targetname, self.target)); )
270 setsize(e, PL_MIN, PL_MAX);
271 e.velocity = trigger_push_calculatevelocity(org, t, self.height);
273 if(e.movetype == MOVETYPE_NONE)
274 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
281 objerror ("Jumppad with nonexistant target");
286 // exactly one dest - bots love that
287 self.enemy = find(world, targetname, self.target);
291 // have to use random selection every single time
299 setsize(e, PL_MIN, PL_MAX);
300 e.velocity = self.movedir;
302 waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
310 * target: target of jump
311 * height: the absolute value is the height of the highest point of the jump
312 * trajectory above the higher one of the player and the target.
313 * the sign indicates whether the highest point is INSIDE (positive)
314 * or OUTSIDE (negative) of the jump trajectory. General rule: use
315 * positive values for targets mounted on the floor, and use negative
316 * values to target a point on the ceiling.
317 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
319 void spawnfunc_trigger_push()
325 self.active = ACTIVE_ACTIVE;
326 self.use = trigger_push_use;
327 self.touch = trigger_push_touch;
332 self.movedir = self.movedir * self.speed * 10;
335 self.noise = "misc/jumppad.wav";
336 precache_sound (self.noise);
338 // this must be called to spawn the teleport waypoints for bots
339 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
342 void spawnfunc_target_push() {}
343 void spawnfunc_info_notnull() {}
344 void spawnfunc_target_position() {}