Hello guys, it’s me again
I want to be able to show a kind of “press LMB to silent kill” icon for my knife weapon whenever the player gets close to the enemy while holding the weapon knife. I know how to draw icon to screen using Canvas Draw Icon, however I am having problem on detecting if player is in the correct distance from enemy.
My knife is a simple instant hit weapon with infinite ammo, and with a weapon range of 39, so the player needs to be close enough to the enemy pawn to be able to hit it. And in the Take Damage Event of the enemy pawn all the animation is played on both the player mesh and enemy pawn mesh, which makes the Execution Knife Sequence to synchronize between player and enemy.
There is the function CanAttack in UTWeapon Class:
function bool CanAttack(Actor Other)
Which is responsible to detect if the player holding weapon is in range for attacking the enemy, so I have changed this function a bit, by adding a new variable to my knife weapon class:
var bool KnifeKillRange;
Down there in the function is this statement:
// check that target is within range
Dist = VSize(Instigator.Location - Other.Location);
if (Dist > MaxRange())
{
return false;
}
So then I just added this new statement which is related to weapon range instead of MaxRange:
//chech if the target is within weapon range////////////////////////////////////////////////////////////////
if ( Dist <= WeaponRange )
{
return true;
KnifeKillRange = true;
}
if ( Dist > WeaponRange )
{
return false;
KnifeKillRange = false;
}
//chech if the target is within weapon range////////////////////////////////////////////////////////////////
And for testing, as I did not find any mention to Tick Event on UTWeapon, so just for having a imediate feedback, I added this function in the fireammunition function to check if the player is in the correct distance and log the result for me:
simulated function FireAmmunition()
{
if (KnifeKillRange == true)
{
`Log("Press LMB to Silent Kill");
}
if (KnifeKillRange == false)
{
`Log("You are not in range for Silent Kill");
}
super.FireAmmunition();
}
The code compiled correctly, without any errors or warnings, however, the problem is that the check distance is not working, because my variable KnifeKillRange always is set to false.
The only log message I receive is “You are not in range for Silent Kill”.
Any help?
Cheers