From e0394ef16a56cbc21996680bc2b4c65ea7158283 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Fri, 24 Jan 2025 14:07:33 -0500 Subject: [PATCH] Added flags for angle handling on bounce Allows for keeping the current angle on bounce or modifying the pitch. --- src/playsim/actor.h | 2 ++ src/playsim/p_map.cpp | 12 +++++++++--- src/playsim/p_mobj.cpp | 9 +++++++-- src/scripting/thingdef_data.cpp | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 14f04e9ee4..edd04cee5f 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -548,6 +548,8 @@ enum ActorBounceFlag BOUNCE_BounceOnUnrips = 1<<16, // projectile bounces on actors with DONTRIP BOUNCE_NotOnSky = 1<<17, // Don't bounce on sky floors / ceilings / walls BOUNCE_DEH = 1<<18, // Flag was set through Dehacked. + BOUNCE_KeepAngle = 1<<19, // Don't change yaw when bouncing off a surface. + BOUNCE_ModifyPitch = 1<<20, // Change pitch when bouncing off a surface. BOUNCE_TypeMask = BOUNCE_Walls | BOUNCE_Floors | BOUNCE_Ceilings | BOUNCE_Actors | BOUNCE_AutoOff | BOUNCE_HereticType | BOUNCE_MBF, diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index aaa45e4dc6..04ffa12c06 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -3653,7 +3653,8 @@ bool FSlide::BounceWall(AActor *mo) } moveangle = mo->Vel.Angle(); deltaangle = (lineangle * 2) - moveangle; - mo->Angles.Yaw = deltaangle; + if (!(mo->BounceFlags & BOUNCE_KeepAngle)) + mo->Angles.Yaw = deltaangle; movelen = mo->Vel.XY().Length() * GetWallBounceFactor(mo); @@ -3751,8 +3752,10 @@ bool P_BounceActor(AActor *mo, AActor *BlockingMobj, bool ontop) DAngle angle = BlockingMobj->AngleTo(mo) + DAngle::fromDeg((pr_bounce() % 16) - 8); double speed = mo->VelXYToSpeed() * GetWallBounceFactor(mo); // [GZ] was 0.75, using wallbouncefactor seems more consistent if (fabs(speed) < EQUAL_EPSILON) speed = 0; - mo->Angles.Yaw = angle; - mo->VelFromAngle(speed); + if (!(mo->BounceFlags & BOUNCE_KeepAngle)) + mo->Angles.Yaw = angle; + mo->Vel.X = speed * angle.Cos(); + mo->Vel.Y = speed * angle.Sin(); mo->PlayBounceSound(true, 1.0); } else @@ -3781,6 +3784,9 @@ bool P_BounceActor(AActor *mo, AActor *BlockingMobj, bool ontop) mo->Vel *= mo->bouncefactor; } + if (mo->BounceFlags & BOUNCE_ModifyPitch) + mo->Angles.Pitch = -VecToAngle(mo->Vel.XY().Length(), mo->Vel.Z); + mo->PlayBounceSound(true, 1.0); if (mo->BounceFlags & BOUNCE_MBF) // Bring it to rest below a certain speed { diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 61d54c2ece..9bc1854719 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -1824,7 +1824,8 @@ bool AActor::FloorBounceMissile (secplane_t &plane, bool is3DFloor) if (BounceFlags & (BOUNCE_HereticType | BOUNCE_MBF)) { Vel -= norm * dot; - AngleFromVel(); + if (!(BounceFlags & BOUNCE_KeepAngle)) + AngleFromVel(); if (!(BounceFlags & BOUNCE_MBF)) // Heretic projectiles die, MBF projectiles don't. { flags |= MF_INBOUNCE; @@ -1838,9 +1839,13 @@ bool AActor::FloorBounceMissile (secplane_t &plane, bool is3DFloor) { // The reflected velocity keeps only about 70% of its original speed Vel = (Vel - norm * dot) * bouncefactor; - AngleFromVel(); + if (!(BounceFlags & BOUNCE_KeepAngle)) + AngleFromVel(); } + if (BounceFlags & BOUNCE_ModifyPitch) + Angles.Pitch = -VecToAngle(Vel.XY().Length(), Vel.Z); + PlayBounceSound(true, 1.0); // Set bounce state diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index fa8d666748..8692936c11 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -407,6 +407,8 @@ static FFlagDef ActorFlagDefs[]= DEFINE_FLAG2(BOUNCE_NotOnShootables, DONTBOUNCEONSHOOTABLES, AActor, BounceFlags), DEFINE_FLAG2(BOUNCE_BounceOnUnrips, BOUNCEONUNRIPPABLES, AActor, BounceFlags), DEFINE_FLAG2(BOUNCE_NotOnSky, DONTBOUNCEONSKY, AActor, BounceFlags), + DEFINE_FLAG2(BOUNCE_KeepAngle, KEEPBOUNCEANGLE, AActor, BounceFlags), + DEFINE_FLAG2(BOUNCE_ModifyPitch, BOUNCEMODIFIESPITCH, AActor, BounceFlags), DEFINE_FLAG2(OF_Transient, NOSAVEGAME, AActor, ObjectFlags),