Fighting game - How to always make fighters face each other?

So what I did was take the side scroller template and turned it into a fighting game template with a some simple tweaking for instant left and right turns.

The branch in the above pic is so that once player jumps they can’t change jump mid flght.

The situation now is how to make the players always instantly snap and rotate to face each other once a threshold is crossed.

I imagine that the the “get look at rotation” will be integral to this functionality but I have not got it yet. Any ideas how to accomplish this ability for a fighting game? Thanks.

Ok, here is how I got to work. As always there is probably a ton of ways to do this in UE4, but this is how I achieved it.

As stated above I used the side scroller template, so I duplicated the side scroller player character as player 2.

You are going to want to make a really…really…big box collision to attach to the player. Name it “P2 A box”. It will be in front of the player or facing right for the fighting game.

Here is the L R S I used…


Now…duplicate the A box and rename it “P2 B box”. I changed the 8000 to -8000 so it just moved the duplicated box position to behind the player or to the left for a fighting game.


The boxes should now be back to back. Meeting in the middle of the player, the A box to the right, the B box to the left.

The video below tries to show that.

Add the following code to your second player BP…

Don’t forget to choose side scroller character (not 2) in the “Get Actor Of Class” node.

In player 1 you will not have to use the A, and B box system, instead, simply add the following code…

Don’t forget to choose side scroller character 2 in the “Get Actor Of Class” node.

The effect should be working now…demonstrated in the video below.

While this works, I still keep thinking there is a better way to do this without the collision boxes. Perhaps I just need to check from one player if the player’s capsule is either to the left or right of the player and then rotate accordingly.

I was able to make something that is much cleaner and should be better in the long run.

Place this set of nodes in your character(s) BP. It can be the same for the 2 player just make sure on the “get actor of class” to seek for the other player.

This is much simpler, no collision boxes…same code / logic for each player.

1 Like

Hey man I tried to do this exact same code but it don’t seem to work. Can you help me with this please?

1 Like

For sure, well I was using UE4 when I made this. Are you using 4 or 5? It is doing anything? Describe your situation.

I am actually behind when comes to the fighting game template. I have spent most of my time in the Beat Em Up template.

Where I talk about using box collisions for this, I thought I figured out a way to do it without box collisions. Just by checking which player is facing and adjusting rotation accordingly.

The other day I found an old Fighting Game project where I managed to figure how to get them to turn without box collisions. This is a lot cleaner doing it this way.

Bare in mind I do not know how fighting games actually do that mechanism, but to me it looks like as soon as you jump over them your character and theirs instantly flip to face each other. The above code will do just that.

It seems I used a side scroller character inside a third person template lol.

  1. Make two boolean variables “Facing Left?” and “Facing Right?”.
  2. Add a custom event “Facing”.

Drag out from an Event Tick to a "Get Actor Of Class"Set it to your second or other player. From its EXEC out drag out and call Facing. Drag out from that to a compare float.

Go back to the Get Actor Of Class and drag from its blue return value pin and get capsule component (of the other player), drag out from that to a “Get World Location”. Right click on its vector output and “Split struct pin” to get access to individual X, Y, Z,. In this case we only need the left and right or Y, drag out and plug that into the input of the compare float.

Drag in your capsule component from components…Drag that out to a “Get World Rotation”, again Split Struct Pin, we only need Z here, you are going to need TWO greater than but equal to (>=) nodes and TWO less than but equal to (<=) nodes. Set your variables and plug them in as shown in the diagram being exec fed by your red “Facing” custom event.

Once again drag in your capsule component and drop it under where the other players capsule shows on the grid. Drag out to a Get World Location, get the Y and plug that into the bottom of the compare node.

Now…out of the top and bottom exec of the compare node we need TWO “Set Actor Rotation” nodes. On the top node set the Z to 90, and the bottom Z to -90, conversely, if you find this is backwards for you, then simply reverse it.

Hope this helps.