Resident Evil 4 Style Aiming Window - Rotational Problem When Aiming
I am trying to create a Resident Evil 4 - Style "Aimbox window". I have made a lot of progress to my the current build of my game -- However my solution for Aiming my gun within bounds isn't working.
I want to move the gun independently of the body when in aiming mode, however, when I move the gun out of bounds (degrees based on the relative position fo the player) I want the entire body to move with the gun synchronously.
My current solution is overly complex. It is not usually my style to ask for help, but I really could use some. The game works with regular rotation, however, i really have my mind set on this feature.
NOTES:
my current solution involves lots of if checks and Euler angles.
for example I often add 360f to the right bound to make it so the gun is within bounds between left bound @ 350 degrees and right bound at 20 degrees -- I HAVE A LOT janky rotational fixes
I have a rotational problem where the gun spins $$anonymous$$UCH faster outside the 'aimbox bounds' .... However localEulerAngles (of the child gun and parent body) say 50 degrees difference, when in actuality, they're 180 degrees apart
Answer by meatcarnage · Oct 16, 2019 at 09:56 AM
Wow. fixed it in 3 lines and deleted some janky inefficient code:
gun.transform.rotation = Quaternion.Euler(-rotationX, rotationY, 0);
// If you move the lasersight out of bounds
if (angleDiff > 50f)
{
playerBodyPivotAim.transform.rotation = Quaternion.Lerp(playerBodyPivotAim.transform.rotation, gun.transform.rotation, bodyAimFollow);
}