9 float trigger_push_calculatevelocity_flighttime;
12 trigger_push_calculatevelocity
15 org - origin of the object which is to be pushed
16 tgt - target entity (can be either a point or a model entity; if it is
17 the latter, its midpoint is used)
18 ht - jump height, measured from the higher one of org and tgt's midpoint
20 Returns: velocity for the jump
21 the global trigger_push_calculatevelocity_flighttime is set to the total
25 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
27 local float grav, sdist, zdist, vs, vz, jumpheight;
28 local vector sdir, torg;
30 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
32 grav = cvar("sv_gravity");
34 zdist = torg_z - org_z;
35 sdist = vlen(torg - org - zdist * '0 0 1');
36 sdir = normalize(torg - org - zdist * '0 0 1');
38 // how high do we need to push the player?
39 jumpheight = fabs(ht);
41 jumpheight = jumpheight + zdist;
46 You will not understand the following equations anyway...
47 But here is what I did to get them.
52 z(t) = t * vz - 1/2 grav t^2
58 max(z, ti) = jumpheight
60 From these three equations, you will find the three parameters vs, vz
64 // push him so high...
65 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
67 // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
73 solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist"
74 // ALWAYS solvable because jumpheight >= zdist
76 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)
78 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)
85 // almost straight line type
86 // jump apex is before the jump
87 // we must take the larger one
88 trigger_push_calculatevelocity_flighttime = solution_y;
93 // jump apex is during the jump
94 // we must take the larger one too
95 trigger_push_calculatevelocity_flighttime = solution_y;
103 // almost straight line type
104 // jump apex is after the jump
105 // we must take the smaller one
106 trigger_push_calculatevelocity_flighttime = solution_x;
111 // jump apex is during the jump
112 // we must take the larger one
113 trigger_push_calculatevelocity_flighttime = solution_y;
116 vs = sdist / trigger_push_calculatevelocity_flighttime;
118 // finally calculate the velocity
119 return sdir * vs + '0 0 1' * vz;
122 void trigger_push_touch()
124 // FIXME: add a .float for whether an entity should be tossed by jumppads
125 if (!other.iscreature)
126 if (other.classname != "corpse")
127 if (other.classname != "body")
128 if (other.classname != "gib")
129 if (other.classname != "casing")
130 if (other.classname != "droppedweapon")
131 if (!other.projectiledeathtype || other.classname == "bullet")
134 if (other.deadflag && other.iscreature)
140 self.movedir = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
142 other.flags &~= FL_ONGROUND;
143 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
144 other.oldvelocity = other.velocity = self.movedir;
146 UpdateCSQCProjectile(other);
148 if (other.classname == "player")
150 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
152 // flash when activated
153 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
154 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
155 self.pushltime = time + 0.2;
157 if(clienttype(other) == CLIENTTYPE_REAL)
162 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
163 if(other.(jumppadsused[i]) == self)
167 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
168 other.jumppadcount = other.jumppadcount + 1;
172 centerprint(other, self.message);
175 other.jumppadcount = TRUE;
178 if(self.enemy.target)
188 // reset tracking of who pushed you into a hazard (for kill credit)
191 if (other.flags & FL_PROJECTILE)
192 other.angles = vectoangles (other.velocity);
194 if (self.spawnflags & PUSH_ONCE)
196 self.touch = SUB_Null;
197 self.think = SUB_Remove;
198 self.nextthink = time;
204 void trigger_push_findtarget()
208 local float flighttime;
210 // first calculate a typical start point for the jump
211 org = (self.absmin + self.absmax) * 0.5;
212 org_z = self.absmax_z - PL_MIN_z;
217 self.enemy = find(world, targetname, self.target);
220 objerror("trigger_push: target not found\n");
225 self.movedir = trigger_push_calculatevelocity(org, self.enemy, self.height);
226 flighttime = trigger_push_calculatevelocity_flighttime;
231 // calculate the destination and spawn a teleporter spawnfunc_waypoint
234 setsize(e, PL_MIN, PL_MAX);
235 e.velocity = self.movedir;
237 self.dest = trace_endpos;
240 waypoint_spawnforteleporter(self, self.dest, flighttime);
246 * target: target of jump
247 * height: the absolute value is the height of the highest point of the jump
248 * trajectory above the higher one of the player and the target.
249 * the sign indicates whether the highest point is INSIDE (positive)
250 * or OUTSIDE (negative) of the jump trajectory. General rule: use
251 * positive values for targets mounted on the floor, and use negative
252 * values to target a point on the ceiling.
253 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
255 void spawnfunc_trigger_push()
257 if (self.angles != '0 0 0')
262 self.touch = trigger_push_touch;
267 self.movedir = self.movedir * self.speed * 10;
270 self.noise = "misc/jumppad.wav";
271 precache_sound (self.noise);
273 // this must be called to spawn the teleport waypoints for bots
274 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
277 void spawnfunc_target_push() {};
278 void spawnfunc_info_notnull() {};
279 void spawnfunc_target_position() {};