As you can see the mouse aim doesnt really work in a an isometric perspective. The projectile is spawned 100 cm above the player pivot point and thus it doesnt actually go exactly in the direction of the mouse cursor.
Reading this it seems you understood that you’re not rotating the capsule correctly to your mouse cursor position. I assume the direction of your projectile is dependent on this rotation.
As far as I know GetHitResultUnderCursorByChannel does nothing else than tracing from your camera position to your mouse location in world space. So everything you need to do is to move back from the HitResult location into the negative direction of the trace to the height where your projectiles are spawned. The result is a vector you want to plug into the Target input of your FindLookAtRotation node. This is nothing but a little vector math.
You’re lucky, I need this in my own project so I quickly implemented this. Simply copying this should work for you but you can also keep your GetHitResultUnderCursor if you want that instead of the trace. Ignore the IsLocallyControlled node with its branch, I set this up for multiplayer. I’m using a SphereTrace because LineTraces are buggy with Landscapes.
I done this for my project.
You must project mouse cursor location to horizontal plane that is on feet (or pelvis) level of character. This helps aiming also solves weird glitches when you move under door frame or behind some obstacles.
I done it with some trigonometry (solving 2 triangles and some angle, basic math), but recently i found node to project point on plane (sadly forgot exact name of that node).
So find that node and calculate projection point. This will safeguard mouse cursor locations as well, you can even build in more user-proof logic there.
That was years ago for UE4.2 or something like that, i have backups somewhere, with a bit of luck i can dig it out and make screenshot.
It is really just some simple trigonometry. Draw triangles from camera location, to mouse cursor and where real location on floor plane should be.
Built in calculations for real mouse location was picking door frames, some decorations etc, and i wanted REAL location on floor plane for AI, so i made that trig calculations myself.
Will try to find it.
Small update: i think i have that project, but it was done with dungeon architect plugin and its 4.11 version of engine. (cannot be loaded with other versions unless i have dungeon architect for it). So i will try to get it for 4.26 or install 4.11.
I found this, it is 4.11 and i forgot what title on big comment really means. Some though shortcut, but i forgot it.
This is optimized version that uses unreal functions, i have somewhere older version made out of camera location and mouse screen location and much more trigonometry than this.
This assumes floor level at 0,0,0, if different level above 0 you add second offset to pelvis offset
I remember how it is calculated:
You have world location and forward vector for camera looking at mouse pointer. This is vector and location for where pointer is in 3d relative to camera.
From world location you can get length of one side of triangle (it is height of camera above horizontal plane)
Also cosinus alpha is cosinus of angle beetwen vertical vector and vector your camera is looking at mouse pointer.
So simple trig gives you distance you looking for: Height/cos(alpha).
Now you have camera forward vector and its length, you can multiply that, add to world location of camera, and you get where on ground plane mouse pointer really is.
It is hard to remove any offset between where you are aiming and where mouse pointer is, because your character usually shoots from hip (or shoulder) height, and this adds visible offset. However this calculation shoots at point exactly above mouse, if you shot from pelvis it will shoot at 90 units above ground.
For extra precise aiming you need use animation blueprint, find there exact direction weapon needs to shoot at target, then use aim offset to rotate weapon correctly, and shoot along forward vector of weapon.
You need both calculations. Mine to find where on floor plane is mouse (for walking), and accurate 3d line trace, when you aim at enemy.
But for top down games do not overdo with accuracy etc. Spending 3 months to get perfect foot placement and weapon aim direction is not worth it for games like that.
@Nawrot, Sir, you are a Star, Thank you very much! It works as i imagine it should!
**“But for top down games do not overdo with accuracy etc. Spending 3 months to get perfect foot placement and weapon aim direction is not worth it for games like that” **
This is the type of feature nobody notices if it works right, but it looks bad when there is a discrepancy between cursor and where player character is actually shooting.
So i want to get it right. I can handle the actual aiming, line trace from player, animBP and all that, but for life of me, i couldn’t figure out the cursor offset thing.
Thank you again!!
@Nawrot thanks for that, you responded so fast what a legend, I have tried it but maybe I am having the idea wrong about this thread, my goal is to have an aiming system similar to the TopDown game called Foxhole,
basically the character aims at the mouse position with a pitch offset to account for projectile height
Which I’m not sure how to do, I have already managed to get the character to aim directly at the mouse postion (no offset) then I have tried to add an offset but the aim point just moves above, instead of like Foxhole how it seems to calculate a distance below the mouse location to then calculate the pitch up and aimrotation from
This is my project the mouse location is the little green circle
I know this is a bit of an older post but I wanted to reply here since I was also looking for a solution and think I found one.
If you first use “Get Hit Result Under Cursor by Channel” and then use this to get a trace start and trace end for a sphere trace, it gave me good results.
I set the radius equal to the capsule half height of the character.
Yes you get good results for flat environments.
But moment you aim at door frame (or tree), your character will get confused.
So solution is either managing such spots to not get in line trace results.
Or use trig to calculate coordinates at feet/pelvis/head height of character.