7 float trigger_push_calculatevelocity_flighttime;
10 trigger_push_calculatevelocity
13 org - origin of the object which is to be pushed
14 tgt - target entity (can be either a point or a model entity; if it is
15 the latter, its midpoint is used)
16 ht - jump height, measured from the higher one of org and tgt's midpoint
18 Returns: velocity for the jump
19 the global trigger_push_calculatevelocity_flighttime is set to the total
23 vector(vector org, entity tgt, float ht) trigger_push_calculatevelocity =
25 local float grav, sdist, zdist, vs, vz, jumpheight, trajsign;
26 local vector sdir, torg;
28 torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
30 grav = cvar("sv_gravity");
32 zdist = torg_z - org_z;
33 sdist = vlen(torg - org - zdist * '0 0 1');
34 sdir = normalize(torg - org - zdist * '0 0 1');
36 // how high do we need to push the player?
37 jumpheight = fabs(ht);
39 jumpheight = jumpheight + zdist;
44 You will not understand the following equations anyway...
45 But here is what I did to get them.
50 z(t) = t * vz - 1/2 grav t^2
56 max(z, ti) = jumpheight
58 From these three equations, you will find the three parameters vs, vz
62 // push him so high...
63 vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)!
68 // how far to push him?
71 trigger_push_calculatevelocity_flighttime = sqrt(jumpheight * 8 / grav);
72 vs = sdist / trigger_push_calculatevelocity_flighttime;
73 // trajsign is ignored (the high point MUST be inside the jump!)
82 // >0: the lower speed that achieves "it"
83 // (parabola's maximum inside the jump)
84 // <0: the higher speed that achieves "it"
85 // (parabola's maximum outside the jump)
87 vs = sqrt(jumpheight - zdist);
88 vs = sqrt(jumpheight) - trajsign * vs; // fteqcc sucks
89 vs = fabs(vs * sqrt(grav/2) / zdist);
90 //vs = fabs((sdist / zdist) * sqrt(grav/2) * (sqrt(jumpheight) - trajsign * sqrt(jumpheight - zdist)));
91 trigger_push_calculatevelocity_flighttime = 1 / vs;
92 // note: vs cannot be zero here. The difference between the sqrts is zero IFF zdist == 0, which we have excluded.
95 // cases to test: "jump up", "jump down" with positive and negative height
98 // finally calculate the velocity
99 return sdir * vs + '0 0 1' * vz;
102 void() trigger_push_touch =
104 // FIXME: add a .float for whether an entity should be tossed by jumppads
105 if (other.classname != "player")
106 if (other.classname != "corpse")
107 if (other.classname != "body")
108 if (other.classname != "gib")
109 if (other.classname != "missile")
110 if (other.classname != "casing")
111 if (other.classname != "grenade")
112 if (other.classname != "plasma")
113 if (other.classname != "plasma_prim")
114 if (other.classname != "plasma_chain")
115 if (other.classname != "droppedweapon")
118 if (other.deadflag && other.classname == "player")
123 other.velocity = self.movedir;
124 other.flags = other.flags - (other.flags & FL_ONGROUND);
128 if (other.classname == "player")
132 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
134 sound (other, CHAN_ITEM, "misc/jumppad.ogg", 1, ATTN_NORM);
135 self.pushltime = time + 0.5;
138 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
139 if(other.(jumppadsused[i]) == self)
143 other.(jumppadsused[math_mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
144 other.jumppadcount = other.jumppadcount + 1;
148 self.movedir = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
150 other.flags = other.flags - (other.flags & FL_ONGROUND);
151 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
152 other.oldvelocity = other.velocity = self.movedir;
153 // reset tracking of who pushed you into a hazard (for kill credit)
156 if (other.classname == "missile")
157 other.angles = vectoangles (other.velocity);
159 if (self.spawnflags & PUSH_ONCE)
161 self.touch = SUB_Null;
162 self.think = SUB_Remove;
163 self.nextthink = time;
169 void() trigger_push_findtarget =
173 local float flighttime;
175 // first calculate a typical start point for the jump
176 org = (self.absmin + self.absmax) * 0.5;
177 org_z = self.absmax_z - PL_MIN_z;
182 self.enemy = find(world, targetname, self.target);
185 objerror("trigger_push: target not found\n");
190 self.movedir = trigger_push_calculatevelocity(org, self.enemy, self.height);
191 flighttime = trigger_push_calculatevelocity_flighttime;
196 // calculate the destination and spawn a teleporter waypoint
199 setsize(e, PL_MIN, PL_MAX);
200 e.velocity = self.movedir;
202 self.dest = trace_endpos;
205 waypoint_spawnforteleporter(self, self.dest, flighttime);
211 * target: target of jump
212 * height: the absolute value is the height of the highest point of the jump
213 * trajectory above the higher one of the player and the target.
214 * the sign indicates whether the highest point is INSIDE (positive)
215 * or OUTSIDE (negative) of the jump trajectory. General rule: use
216 * positive values for targets mounted on the floor, and use negative
217 * values to target a point on the ceiling.
218 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
220 void() trigger_push =
222 if (self.angles != '0 0 0')
225 self.solid = SOLID_TRIGGER;
226 setmodel (self, self.model);
227 self.movetype = MOVETYPE_NONE;
231 self.touch = trigger_push_touch;
236 self.movedir = self.movedir * self.speed * 10;
238 // this must be called to spawn the teleport waypoints for bots
239 self.think = trigger_push_findtarget;
240 self.nextthink = time + 0.2;
243 void() target_push = {};
244 void() info_notnull = {};
245 void() target_position = {};