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, trajsign;
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)!
70 // how far to push him?
73 trigger_push_calculatevelocity_flighttime = sqrt(jumpheight * 8 / grav);
74 vs = sdist / trigger_push_calculatevelocity_flighttime;
75 // trajsign is ignored (the high point MUST be inside the jump!)
84 // >0: the lower speed that achieves "it"
85 // (parabola's maximum inside the jump)
86 // <0: the higher speed that achieves "it"
87 // (parabola's maximum outside the jump)
89 vs = sqrt(jumpheight - zdist);
90 vs = sqrt(jumpheight) - trajsign * vs; // fteqcc sucks
91 vs = fabs(vs * sqrt(grav/2) / zdist);
92 //vs = fabs((sdist / zdist) * sqrt(grav/2) * (sqrt(jumpheight) - trajsign * sqrt(jumpheight - zdist)));
93 trigger_push_calculatevelocity_flighttime = 1 / vs;
94 // note: vs cannot be zero here. The difference between the sqrts is zero IFF zdist == 0, which we have excluded.
97 // cases to test: "jump up", "jump down" with positive and negative height
100 // finally calculate the velocity
101 return sdir * vs + '0 0 1' * vz;
104 void trigger_push_touch()
106 // FIXME: add a .float for whether an entity should be tossed by jumppads
107 if (!other.iscreature)
108 if (other.classname != "corpse")
109 if (other.classname != "body")
110 if (other.classname != "gib")
111 if (other.classname != "missile")
112 if (other.classname != "rocket")
113 if (other.classname != "casing")
114 if (other.classname != "grenade")
115 if (other.classname != "plasma")
116 if (other.classname != "plasma_prim")
117 if (other.classname != "plasma_chain")
118 if (other.classname != "droppedweapon")
121 if (other.deadflag && other.iscreature)
127 self.movedir = trigger_push_calculatevelocity(other.origin, self.enemy, self.height);
129 other.flags = other.flags - (other.flags & FL_ONGROUND);
130 // reset tracking of oldvelocity for impact damage (sudden velocity changes)
131 other.oldvelocity = other.velocity = self.movedir;
133 if (other.classname == "player")
135 if(self.pushltime < time) // prevent "snorring" sound when a player hits the jumppad more than once
137 // flash when activated
138 pointparticles(particleeffectnum("jumppad_activate"), other.origin, other.velocity, 1);
139 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
140 self.pushltime = time + 0.2;
142 if(clienttype(other) == CLIENTTYPE_REAL)
147 for(i = 0; i < other.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
148 if(other.(jumppadsused[i]) == self)
152 other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
153 other.jumppadcount = other.jumppadcount + 1;
157 centerprint(other, self.message);
160 other.jumppadcount = TRUE;
163 if(self.enemy.target)
173 // reset tracking of who pushed you into a hazard (for kill credit)
176 if (other.flags & FL_PROJECTILE)
177 other.angles = vectoangles (other.velocity);
179 if (self.spawnflags & PUSH_ONCE)
181 self.touch = SUB_Null;
182 self.think = SUB_Remove;
183 self.nextthink = time;
189 void trigger_push_findtarget()
193 local float flighttime;
195 // first calculate a typical start point for the jump
196 org = (self.absmin + self.absmax) * 0.5;
197 org_z = self.absmax_z - PL_MIN_z;
202 self.enemy = find(world, targetname, self.target);
205 objerror("trigger_push: target not found\n");
210 self.movedir = trigger_push_calculatevelocity(org, self.enemy, self.height);
211 flighttime = trigger_push_calculatevelocity_flighttime;
216 // calculate the destination and spawn a teleporter spawnfunc_waypoint
219 setsize(e, PL_MIN, PL_MAX);
220 e.velocity = self.movedir;
222 self.dest = trace_endpos;
225 waypoint_spawnforteleporter(self, self.dest, flighttime);
231 * target: target of jump
232 * height: the absolute value is the height of the highest point of the jump
233 * trajectory above the higher one of the player and the target.
234 * the sign indicates whether the highest point is INSIDE (positive)
235 * or OUTSIDE (negative) of the jump trajectory. General rule: use
236 * positive values for targets mounted on the floor, and use negative
237 * values to target a point on the ceiling.
238 * movedir: if target is not set, this * speed * 10 is the velocity to be reached.
240 void spawnfunc_trigger_push()
242 if (self.angles != '0 0 0')
247 self.touch = trigger_push_touch;
252 self.movedir = self.movedir * self.speed * 10;
255 self.noise = "misc/jumppad.wav";
256 precache_sound (self.noise);
258 // this must be called to spawn the teleport waypoints for bots
259 InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
262 void spawnfunc_target_push() {};
263 void spawnfunc_info_notnull() {};
264 void spawnfunc_target_position() {};