Pitch rotation problem with FindLookAtRotation function

Hello everyone! Can you please help me with this?

I’m trying to create a 2D platformer where player can shoot at any angle (not just 8 direction like in a classic games). My decision was to separate the player character sprite to two - lower body and upper body. The upper body sprite should follow the mouse in 360 degree range.

To calculate the rotation angle of the upper body sprite I use GetHitResultUnderCursorByChannel and trace my mouse to the plane just behind the character (the result is represented as red debug sphere on video)

Then I use FindLookAtRotation with ActorLocation as a starting point (green debug sphere on video) and my mouse hit result location as target point. Then I use Y(pitch) value from the result to set my upper body sprite Y angle.

With all that I get very strange angle values (see the video, angle is printed). This same logic works well with rotating on Z axis so I admit the gimbal lock problem here. I saw this topic

How can I avoid Gimbal Lock with Rotations?

but I’m not sure how to apply that solution to my problem and if it’s the case at all.

So the questions are:

  1. How can I solve this problem and get normal angle values from 0 to 360 or something?
  2. Is this even a good logic for such a gameplay mechanic?

Thanks

Video - record_2025-04-13_00-07-15.mp4 - Google Drive

Angle calculation function

Somehow I managed to get the right 0 to 360 angle values. Problem was in how FindLookAtRotation result behaves.

This is the working function for calculating the angle. Maybe it will help someone.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.