This is my first post here. I am a complete newbie (been studying UE5 for a week or so). I want to create an old fashioned point 'n click adventure game, in the style of The Secret of Monkey Island.
I’m afraid I got stuck early on in the process. I am trying to get the player character to “turn around” (i.e. for the sprite to flip horizontally) when I click the left mouse on a location that is opposite to the location that they are facing. So for example, if I click where the cursor is in the following picture, then the character should face to the left.
The way I figured out to go about it is this: Get the player location, and if the mouse click happens to its right, then use the “walk right” animation (flipbook). If it happens to its left, then use the “walk left” animation. I tried out some node trees like the abomination that you see below, but I guess I lack the knowledge and experience to understand what I’m doing wrong.
I apologize if my description is not 100% clear. Please bear with me, as - again - I just started working with UE (I’m using version 5.0.1 btw).
Thank you so much in advance for any help or guidance!
EDIT: I made some progress, now the flipbook changes when the mouse pointer moves from the left to the right of the character and vice versa, but I don’t want it to do that; I want it to change when I click somewhere in the map. So I guess all that’s left is to figure out how to tell it to look for the coordinates when I click the left mouse button.
Hi,
You are comparing a mouse position(which can be between x=1920 y=1080 on 1080p screen) and world position of an object which has no relation to screen position. Check out this video if it helps: WTF Is? Project World to Screen in Unreal Engine 4 ( UE4 ) - YouTube
You basically need to convert the world position of an object to where it is on the screen.
First of all, a big thanks to @Polysiens for pointing out what I was doing wrong in comparing the two positions (mouse and capsule component). This time I used a Convert Mouse Location To World Space instead, to track the location of the mouse cursor.
To mirror the sprite, I had two options: Either rotate it by 180 degrees on its Z axis, or just create another sprite sheet in my pixel art software with the sprite mirrored along the Z axis and set two different flipbooks for each of the Compare Float results. I tried the former for economy reasons, but I couldn’t get it to work. The sprite kept getting turned upside down instead of turning around. I think it has to do with the fact that the scene is top down, i.e. the background is laid along the XY plain instead of the XZ one. I tried several rotation functions and axes, to no avail. So I just tried rotating the sprite with a negative scale and it worked. Here’s my solution:
This works together with a simple move to location on LMB click and a velocity check to see if the player is moving or not. Here’s the result:
Now I want to make him use the proper animation when he’s walking “away” or “towards” the screen (quotation marks since we’re talking about 2D, obviously). But that’s a different fight
Thank you again, @Polysiens for your valuable help!