Aiming in a 2D sidescroller problem - arrow does not follow the cursor

Hello. I’ve been working on a 2.5D platformer and I’m trying to find a way to shoot projectiles at mouse location. Above the main character there is a floating weapon (for now replaced with an arrow component that will be parented to the gun mesh) that is supposed to rotate in such a way as to allow player to shoot enemies. I’ve been looking these days at several tutorials that could help me with this, but so far nothing works. I should also mention that I’m using Unreal Engine 5.00, in case that there are some changes from the previous versions that might interfere.

One of the things that I tried is from this thread:

That has this Blueprint Graph solution:

However, the arrow component sticks up, moves a little and does not follow the cursor. I posted a gif here to explain, with values print screened for several vectors:
ezgif-4-f152e3c9f0

Another thing that I tried is from this thread:

And it still doesn’t work. The rotation value goes from 86 to 87 so the arrow stays almost still.

Do you know how could I solve this problem ? I would really need help with this.

1 Like

You have to project your mouse to the same y location as you character.
Here an example on how to do it.

3 Likes

Thank you very much ! I tried using your example script, and the arrow does indeed follow the cursor.

There is still a little problem. The arrow is not pointing just in XZ plane, it is pointing a bit outwards, in the Y axis. This could cause problems at a later stage, when shooting is implemented. I also tried to attach a gun mesh to the arrow, and it seems that the gun has another kind of rotation, in order to point outwards. I wonder how could I constrain the movement of the weapon/arrow in a single plane, like in 2D games.

Check if your character model is centered inside of the character actor. But to me it looks like your camera has an angled view on the scene. To fix this either remove the camera angle or adjust the solution to the follwing:

To lock your character in the XZ plane use the settings inside of the CharacterMovementComponent:
grafik

1 Like

I verified and the camera doesn’t have an angled view. However, it is turned at -90.000183 ° on the Z axis. I’m not sure that that approximation caused the issue. Anyway, I tried using the modified script, and everything works well. Thank you very much for your help !