From 3873ad61513ea07ad31294ee439c46ac97917062 Mon Sep 17 00:00:00 2001 From: sgrunt Date: Thu, 18 Mar 2021 07:19:00 -0600 Subject: [PATCH] Fix behaviour of VelIntercept's oldvel parameter Previously Vel would be reset only if the target was moving. This change ensures that Vel is always reset, as seems to be the intent of the oldvel parameter. --- src/playsim/p_things.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/playsim/p_things.cpp b/src/playsim/p_things.cpp index 7e000a74a..12d685952 100644 --- a/src/playsim/p_things.cpp +++ b/src/playsim/p_things.cpp @@ -175,6 +175,7 @@ static void VelIntercept(AActor *targ, AActor *mobj, double speed, bool aimpitch { if (targ == nullptr || mobj == nullptr) return; + DVector3 prevel = mobj->Vel; DVector3 aim = mobj->Vec3To(targ); aim.Z += targ->Height / 2; @@ -198,6 +199,10 @@ static void VelIntercept(AActor *targ, AActor *mobj, double speed, bool aimpitch if (targ->Vel.X == 0 && targ->Vel.Y == 0) { InterceptDefaultAim(mobj, targ, aim, speed); + if (oldvel) + { + mobj->Vel = prevel; + } return; } } @@ -207,7 +212,6 @@ static void VelIntercept(AActor *targ, AActor *mobj, double speed, bool aimpitch double a = g_acos(clamp(ydotx / targspeed / dist, -1.0, 1.0)); double multiplier = double(pr_leadtarget.Random2())*0.1 / 255 + 1.1; double sinb = -clamp(targspeed*multiplier * g_sin(a) / speed, -1.0, 1.0); - DVector3 prevel = mobj->Vel; // Use the cross product of two of the triangle's sides to get a // rotation vector. DVector3 rv(tvel ^ aim); @@ -221,10 +225,6 @@ static void VelIntercept(AActor *targ, AActor *mobj, double speed, bool aimpitch // And make the projectile follow that vector at the desired speed. mobj->Vel = aimvec * (speed / dist); mobj->AngleFromVel(); - if (oldvel) - { - mobj->Vel = prevel; - } if (aimpitch) // [MC] Ripped right out of A_FaceMovementDirection { const DVector2 velocity = mobj->Vel.XY(); @@ -235,6 +235,10 @@ static void VelIntercept(AActor *targ, AActor *mobj, double speed, bool aimpitch { InterceptDefaultAim(mobj, targ, aim, speed); } + if (oldvel) + { + mobj->Vel = prevel; + } } DEFINE_ACTION_FUNCTION(AActor, VelIntercept)