Sidescroller game movement depending on mouse position

Hey guys,

It’s the first time that i’m practicing with a playable character on unreal, and i’m a little bit confused.
In fact I recently wanted to start I quick project based on the sidescroller template from Unreal.
My goal is really basic : making my 2d character facing my mouse no matter wich direction he’s going.

Based on the template, the player can only move on the Y axis ( he is always running forward )
My idea is to keep this basic movement ( left or right ), but I’m searching for a way to constrain the movement :

  1. If I want to move to the right with my mouse to the left, I want the player to walk backward.
  2. ( let say I keep running to the right, but in this scenario the mouse is to the right ) then the character is running forward

Here is a basic example of the system i’m trying to reach :

As you can see the player is always looking to the mouse :stuck_out_tongue:
( Do not consider the aiming system, i’m just looking for a way to make the body facing the mouse )

First, I started a quick code to tell unreal when I consider my mouse to be in the “left or right” position

I also changed the animBP to allow the character to walk backward if my player speed is negative.

I would say that’s where i’m confused, I have no idea where to start.
I would really appreciate some advice, ideas to help me solving this problem !
Thanks to everyone who takes the time to reply to this :smiley:

Best regards,

I finally found a simple solution to my problem

  1. Basically for those who are dealing with the same issue, you just have to go to your character settings and play with " orient rotation to direction" option.

236340-answerr.png

fig1 : The option you need to tweak

  1. Then I created a function to analyse where the mouse is ( compared to my actor postion ).

3.I also made a function to know which side my player is facing. ( left / right )

  1. And finally by playing with those two functions you can make your player facing the mouse like this :

236339-gifmovement.gif

If you have any question about that, feel free to ask me :stuck_out_tongue:
Cheers

Hi there! I myself am trying to do something like this! Did you use an aim offset?