forked from id/quake-qw-qc
trigger_push: add support for the target field, for Q3A styled jump pads
This commit is contained in:
parent
d3ad75e188
commit
6611c57cbf
1 changed files with 49 additions and 0 deletions
49
triggers.qc
49
triggers.qc
|
@ -601,8 +601,57 @@ void() trigger_hurt =
|
|||
|
||||
float PUSH_ONCE = 1;
|
||||
|
||||
float(float value) sqrt = #62;
|
||||
|
||||
vector
|
||||
trigger_push_velfortarget(vector vecFrom, vector vecTo, float flGravMod)
|
||||
{
|
||||
float flHeight, flGravity, flTime, flDistance, flDir;
|
||||
vector vecJump = [0,0,0];
|
||||
|
||||
if (flGravMod <= 0.0)
|
||||
flGravMod = 1.0f;
|
||||
|
||||
flGravity = cvar("sv_gravity") * flGravMod;
|
||||
flHeight = vecTo[2] - vecFrom[2];
|
||||
|
||||
/* this may not be a much verticality to this jump, use distance instead */
|
||||
if (flHeight <= 0) {
|
||||
flHeight = vlen(vecTo - vecFrom);
|
||||
flTime = flHeight / flGravity;
|
||||
} else {
|
||||
flTime = sqrt(flHeight / (flGravity * 0.5f));
|
||||
if (flTime <= 0) {
|
||||
return [0,0,0];
|
||||
}
|
||||
}
|
||||
|
||||
vecJump = vecTo - vecFrom;
|
||||
vecJump[2] = 0;
|
||||
flDistance = vlen(normalize(vecJump));
|
||||
|
||||
flDir = flDistance / flTime;
|
||||
vecJump *= flDir;
|
||||
vecJump[2] = flTime * flGravity;
|
||||
|
||||
return vecJump;
|
||||
}
|
||||
|
||||
void() trigger_push_touch =
|
||||
{
|
||||
/* if our trigger_push has a target, bah */
|
||||
if (self.target) {
|
||||
entity targetPos = find(world, ::targetname, self.target);
|
||||
vector pushCenter = ( self.absmin + ( 0.5 * ( self.absmax - self.absmin ) ) );
|
||||
|
||||
if (targetPos) {
|
||||
self.movedir = targetPos.origin;
|
||||
}
|
||||
|
||||
other.velocity = trigger_push_velfortarget(pushCenter, self.movedir, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (other.classname == "grenade")
|
||||
other.velocity = self.speed * self.movedir * 10;
|
||||
else if (other.health > 0)
|
||||
|
|
Loading…
Reference in a new issue