trigger_push: add support for the target field, for Q3A styled jump pads

This commit is contained in:
Marco Cawthorne 2023-07-15 19:38:42 -07:00
parent d3ad75e188
commit 6611c57cbf
Signed by: eukara
GPG key ID: CE2032F0A2882A22

View file

@ -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)