I have a setup where the camera is fixed in rotation, pointing somewhat at a 30 degree angle down at a character. Similar to what you might see in an ISO style game.
I am looking to start setting up attack actions. The idea is, when you left click, you will attack in the direction of the mouse. If this was top-down, it would be much easier.
So far, I have found two potential ways of accomplishing this (though I couldn’t get either to work). Firstly is the “Convert Mouse Location to World Space”. There doesn’t appear to be a doc for this so I’m not sure exactly how it is supposed to function. The idea here would be to perform a Line Trace By Channel from a point in the world above the player to the ground, assuming the mouse location was at ground level.
The problem here is I have no idea how Convert Mouse Location to World Space works. There doesn’t appear to be any documentation for it. There is obviously a loss of information since mouse location is in 2D and the world space is in 3D, but what is it actually using? I performed a few tests with this and got some wild results I couldn’t comprehend. I have no idea how this is supposed to work.
Second is Get Hit Result Under Cursor By Channel
This worked… somewhat. It allowed me to easily obtain the location of the clicked object. Then I could calculate a rotation from the player’s location to the clicked location. The problem is … what if the player clicks themselves?
If the player clicks in the area indicated here:
the end result should be that the player attacks away from the camera. But since the player is returned as a hit actor and I can’t tell it to ignore the player, the end result is attacking towards the camera. Overall this method doesn’t seem very reliable simply because the direction the player attacks in should not be affected by other objects in the world.
I was going to implement a more crude system where I didn’t convert anything, I simply looked at the 2D coordinates of where they clicked. If it’s on the top half of the screen, attack up. Right side, attack right. Etc. I suppose this would work for melee attacks but I do eventually want projectiles as well and I will need the capability of determining the trajectory from where the player is facing to where they clicked.
So am I going about this all wrong? I’ve found several others attempting similar things but it seems there’s always something just different enough to make it not work for me.
Edit: I found this post which seems like it will cover everything I need. If I don’t post anything else, that fixed it.