Hello guys!
It’s me here annoying again
I added a cool slomo effect whenever the player perform a headshot on the enemy.
The effect is very simple, it’s basically detect the hit bone on the pawn takedamage event (it runs on the enemy pawn class):
//this variable is to identify the hit location
local name HitBone;
HitBone = Mesh.FindClosestBone(HitLocation);
//this statement will check if the enemy was attacked by bullet weapons to play the hitbones animations and death
//we are isolating the hitbones detection only to bullet weapons
//also we don't need Headhosts nor hit reaction animations whenever using RPG7
if (DamageType != class'UTDmgType_AIKnife' && DamageType != class'UTDmgType_RPG7')
{
//headshot//////////////////////////////////////////////////////
//we also want that headshot effect be triggered only by players (p1 and p2) and not Bots
if(!EventInstigator.PlayerReplicationInfo.bBot)
{
if(HitBone == 'b_Neck' || HitBone == 'b_Head')
{
TopHalfAnimSlot.StopCustomAnim(0.15);
`Log("Headshot");
HeadShotCount = true;
//this function will play the flash animation headshot icon and slomo effect/////////////////
ForEach LocalPlayerControllers(class'PlayerController', localPlayer)
{
SetTimer(0.15,false,nameof(StartSlomo));
SetTimer(0.35,false,nameof(FinishSlomoHeadshot));
}
//this function will play the flash animation headshot icon and slomo effect/////////////////
Super.Suicide();
}
}
//headshot//////////////////////////////////////////////////////
So I set a small timer to sent the pawn to the slomo function:
//this function will turn on slomo for headshots
simulated function StartSlomo()
{
WorldInfo.Game.SetGameSpeed(0.25);
ClearTimer();
}
then after one second (because the slomo effect slows the time), I send the pawn to the finish slomo function:
//this function will turn off slomo
simulated function FinishSlomoHeadshot()
{
local Playercontroller localplayer;
WorldInfo.Game.SetGameSpeed(1);
ForEach LocalPlayerControllers(class'PlayerController', localPlayer)
{
UTPlayerController(localplayer).ConsoleCommand("HeadshotIconAnimStart");
}
ClearTimer();
}
Everything is working perfectly, however, I realized a bug, that happens only with keyboard on PC, but if I use a gamepad (xbox360 controller), this bug does not happen (also it does not happen on consoles PS3 Xbox360). This bug only happens with a keyboard on PC.
The bug is that if whenever the slomo effect begins, the player is pressing any of the moving keys (W,A,S,D), the player pawn continues running to the direction the button was pressed. In example, if whenever the slomo effect began I was running left (pressing A), the player pawn continues to walk left forever, and only stops if I press the key another time.
Any help?
I like the slomo effect, it feels kinda bullet time, but if I can’t solve this problem, I will remove it (slomo effect).
Cheers!