Skip to content

Commit

Permalink
Added flags for angle handling on bounce
Browse files Browse the repository at this point in the history
Allows for keeping the current angle on bounce or modifying the pitch.
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Jan 28, 2025
1 parent 3d2f9e0 commit e0394ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/playsim/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
12 changes: 9 additions & 3 deletions src/playsim/p_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
9 changes: 7 additions & 2 deletions src/playsim/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/thingdef_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down

0 comments on commit e0394ef

Please sign in to comment.