diff --git a/triggers.qc b/triggers.qc index 0d31915..02c6bed 100644 --- a/triggers.qc +++ b/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)