Skip to content

Commit

Permalink
Fix behaviour of VelIntercept's oldvel parameter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgrunt authored and coelckers committed Mar 19, 2021
1 parent cdbae4b commit 3873ad6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/playsim/p_things.cpp
Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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)
Expand Down

0 comments on commit 3873ad6

Please sign in to comment.