Animation Montage and Pathfinding

Hello Everyone,

I consider myself a newbie (only started around Nov 2023) and loving UE5 so far !

I came across a situation using an animation montage and could use some advice.

Here is the scenario.

Game Type: Third Person Action/RPG

I created a montage using an animation in which the character walks forward while dual wielding guns firing in multiple directions. The animations Root Motion is ticked as I do not want the user to be able to click any inputs while the animation fires off.

The animation is triggered by pressing a number key (lets say key #4). From the point the key is pressed, the player character than goes into its animation without any issues visually.

Here are my 2 issues:

  1. Once the animation fires off, if there are any obstructions directly in front of the animation, the player character will simply walk right through it therefore, no collision is being detected and it will not stop/bump into the object in front of the player character.

  2. As I mentioned, part of this animation is firing 2 guns in multiple directions. So what I need to do is spawn a projectile from within the animation in the appropriate directions the guns are facing at the appropriate time the projectile should be spawned from the nozzle of the gun. Another fact to mention is that the 2 guns are separate from the player character skeletal mesh so each gun has its own skeletal mesh along with appropriate sockets set to the barrel of the gun.

There you have it. How would you approach both issues ? For the first, I was thinking some sort of Pathfinding is needed so that the player character would detect a collision and try to walk around it. For the second, I was thinking of handling this with notifies placed at the point of each “gun fired” where I spawn the projectile based on the location and direction of the gun socket.

This is not what “root motion” animations are for. Given your question, I highly recommend you don’t use root motion animations for this.

Animations can have markers. Markers can fire events. Those events can be listened to by the playing actor (the player character in this case.) Thus, you can fire “start ignoring input” and “stop ignoring input” events in the animation, and wire those up to some flag in your character that makes the character ignore input commands.

When it comes to pathfinding, you will want to determine how far ahead of the character to walk when starting the animation, set the walking speed, and use a “move to position” command to start the character walking, then play the animation in sync. If you want 100% perfect foot placement, I recommend using foot IK (you can google for unreal engine foot IK to get good resources.)

When it comes to “fire guns” you can, again, fire markers. Have one marker for “fire left gun” and one marker for “fire right gun.” Add a socket to each of the hands (or guns.) When you get the event from this marker, get the pose of the socket in question from the skeletal mesh, and use that as the origin of the spawned bullet.