Almighty Push


The Problem: Enemies surrounded the player and they had no way of escaping

For the first week of this month, I spent it creating a solution to a problem that has been present for a while and really bothered me. the problem was that if the player got stuck in a corner or was overwhelmed by several enemies surrounding them, they wouldn't really be able to get out of that situation in an effective way. The only way the player would be able to get themselves out of that situation would be to kill enough enemies to create a hole in the cluster of enemies so that they can escape.

The solution I came up with was to give the player the ability to push the enemies away from them. This ability would be an additional pickup in the loot table. The way it works is it would knock back any enemies within a specified radius. The way you would do this if the character is using CharacterMovementComponent is to call the LaunchCharacter() function. This function takes a velocity as a vector and then queues that velocity to be applied to the movement component's velocity. The problem with this is that I am launching the enemies, which are controlled by an AIController following the behavior tree's behavior. That behavior always tells an enemy to move in the direction of the player, which causes it to overwrite the X and Y values of the velocity set by the launch. This means whenever I launch the enemy it would just be launched in the Z direction (Up) because the behavior doesn't affect the up velocity of the character.


The Solution: Force It

After some digging a solution/workaround to my problem.

character->GetCharacterMovement()->StopActiveMovement(); 
character->GetCharacterMovement()->Launch(launchVel); 
character->GetCharacterMovement()->HandlePendingLaunch();

Instead of calling LaunchCharacter() on the enemy, which queues the launch velocity to happen the next available moment, and since that next moment gets overwritten by the controller telling the enemy to move that wouldn't work. So, I learned that I can call the function StopActiveMovement() which stops any movement, and then I call Launch() and HandlePendingLaunch() which forces the launch to occur. These three little function calls gave me the behavior I desired.

Get Lucifer's Hordes

Leave a comment

Log in with itch.io to leave a comment.