Skip to content

Commit

Permalink
Added spawnflags for keep player angles & velocity in trigger_teleport (
Browse files Browse the repository at this point in the history
#747)

* Added spawnflags for keep player angles & velocity in trigger_teleport
Co-authored-by: etojuice <etojuice@yandex.ru>
  • Loading branch information
SmileyAG committed Apr 28, 2022
1 parent 6c47f96 commit 21dab90
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
39 changes: 34 additions & 5 deletions regamedll/dlls/triggers.cpp
Expand Up @@ -1712,6 +1712,10 @@ void CTriggerPush::Touch(CBaseEntity *pOther)
}
}

#define SF_TELEPORT_KEEP_ANGLES 256
#define SF_TELEPORT_KEEP_VELOCITY 512
#define SF_TELEPORT_REDIRECT_VELOCITY_WITH_YAW_DESTINATION 1024

void CBaseTrigger::TeleportTouch(CBaseEntity *pOther)
{
entvars_t *pevToucher = pOther->pev;
Expand Down Expand Up @@ -1766,15 +1770,40 @@ void CBaseTrigger::TeleportTouch(CBaseEntity *pOther)

UTIL_SetOrigin(pevToucher, tmp);

pevToucher->angles = pentTarget->v.angles;
#ifdef REGAMEDLL_ADD
if (!(pev->spawnflags & SF_TELEPORT_KEEP_ANGLES))
#endif
{
pevToucher->angles = pentTarget->v.angles;

if (pOther->IsPlayer())
if (pOther->IsPlayer())
{
pevToucher->v_angle = pentTarget->v.angles;
}

pevToucher->fixangle = 1;
}

#ifdef REGAMEDLL_ADD
if (!(pev->spawnflags & SF_TELEPORT_KEEP_VELOCITY))
#endif
{
pevToucher->v_angle = pentTarget->v.angles;
pevToucher->velocity = pevToucher->basevelocity = g_vecZero;
}

pevToucher->fixangle = 1;
pevToucher->velocity = pevToucher->basevelocity = g_vecZero;
#ifdef REGAMEDLL_ADD
if ((pev->spawnflags & SF_TELEPORT_REDIRECT_VELOCITY_WITH_YAW_DESTINATION) && (pev->spawnflags & SF_TELEPORT_KEEP_VELOCITY))
{
float xy_vel = pevToucher->velocity.Length2D();

Vector vecAngles = Vector(0, pentTarget->v.angles.y, 0);
Vector vecForward;
AngleVectors(vecAngles, vecForward, nullptr, nullptr);

pevToucher->velocity.x = vecForward.x * xy_vel;
pevToucher->velocity.y = vecForward.y * xy_vel;
}
#endif
}

LINK_ENTITY_TO_CLASS(trigger_teleport, CTriggerTeleport, CCSTriggerTeleport)
Expand Down
10 changes: 9 additions & 1 deletion regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
Expand Up @@ -2262,7 +2262,15 @@
]
]

@SolidClass base(Trigger) = trigger_teleport : "Trigger teleport" []
@SolidClass base(Trigger) = trigger_teleport : "Trigger teleport"
[
spawnflags(flags) =
[
256: "Keep angles" : 0
512: "Keep velocity" : 0
1024: "Redirect velocity with yaw from destination" : 0
]
]

// Function entities
@SolidClass = func_bomb_target : "Bomb target zone"
Expand Down

0 comments on commit 21dab90

Please sign in to comment.