Download

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; https://answers.unrealengine.com/questions/16847/request-ray-plane-intersection-point-function.html

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.

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.

@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

mouse_location.PNG[IMG2=JSON]{“data-align”:“none”,“data-size”:“full”,“src”:“https://forums.unrealengine.com/core/image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==”}[/IMG2]​
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.

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