Isometric mouse aim - how to make it precise?

Hi

I am working on a small isometric shooter with mouse aim. I am loosely following the Twin Stick Shooter tutorial; Blueprint Twin Stick Shooter | v4.8 | Unreal Engine - YouTube

However in my game the the player rotates towards the cursor and the camera angle is more isometric.

I have a problem with the weapon aim though. Please have a look;

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.

I have been looking around and found a few things that might be relevant; How do I create a Blueprint function to find the intersection point of a ray and a plane? - Blueprint - Unreal Engine Forums

And; Unreal Engine 4: Blueprints tutorial - Pawn mouse rotation - YouTube

Am I correct the above threads are dealing with this issue? Its all going a little over my head so if anyone would like to elaborate a little more that would be much appreciated :slight_smile:

Thanks

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.

Yeah I actually did try to break the hitresult and add 100cm to the z vector and feed that into the findlookatrotation. However that didnt really seem to work either.

Would you be kind and elaborate a little on how to do this? I am really not much of a coder unfortunately but I am trying the best I can :slight_smile:

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.

2 Likes

Thats fantastic, thank you so much! :slight_smile: Thats really generous of you!

Hi Pepeeee, just wanted to say thanks again - I just implemented your solution and it worked beautifully :slight_smile:

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.

1 Like

@Nawrot Would it be possible to provide more detailed explanation? i am really struggling with it. screenshot of your setup would be most appreciated.

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

https://forums.unrealengine.com/core/image/gif;base64
​
Ps.
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.

Pps.
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.

2 Likes

@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!!

hey just wondering if you have still have the picture of the logic? I am trying to follow your written explanation but am finding it difficult

I found two pictures with this, and i remember doing this calculations, just cannot find project with it.

First picture is older, but has formula to calculate it all:

This has some errors (just don’t remember what)

And newer picture:

And this may be all wrong pictures. :wink:
And and yes those pictures are wrong (for similar problem but different).

This problem comes back regularly, so i ma make tiny tut/solution if its needed.

PS. if i find backup of that project i may post new pics.

PPS. backup of a backup is far far away, will get to it in april or so. Deleted local backups to make space because i have backups in another place, then i forgot to restore local backups.

1 Like

@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,


https://www.youtube.com/watch?v=NXD8h0bkEAg&ab_channel=Nagoty

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
image

1 Like

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.

Here’s what I got:

The result is that now the characters always hit directly on my mouse cursor.

Old way simply with the “Get Hit Result Under Cursor by Channel”:

New way with sphere trace:

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.

Yea my solution was to just provide a flat invisible grid with a custom “mouse collision” channel that sits on the ground.

1 Like

I do the same thing for mouse collision. I use a dedicated plane that is used for mouse collision only.

This works! I’ve linked other UE threads asking the same question to this post.
Thank you so much!

Did you ever find a working solution for this? I’m trying to replicate this exact thing but I haven’t been able to.