I’m working through adding mouse and keyboard support for my 2D game, which is turning into a bit of a nightmare since i initially learned the wrong (or old) input system and ended up having to strip almost everything out to replace with the new input sytem so i’m able to easily detect controller scheme switching.
Anyway, Thats (kind of) done now but an issue i’m running into is due to the way my character aims (the weapon orbits the player character) When using a gamepad this works perfectly, i’ve modified my logic to accomodate for mouse input as opposed to analog stick input and again, it “kind of” works.
Basically, if the mouse gets too close to the character the weapon sprite seems to duplicate and rotate in a strange way. So the question is does anyone have any suggestions / ideas on how i could prevent this?
I few things i’ve tried:
- Attempting to detect if my mouse is insite the characters CapsuleCollider2D using
playerRigidBody.OverlapPoint(Input.mousePosition);This didn’t work, no matter what i did i couldn’t get a true from it. - Attempting to manually detect if the mouse is “close” to the character using the various values from within my mouse aiming code but this got overly complex very quickly and started to make me want to stab myself in the eye to releive the brain ache

Here’s my mouse aim code:
This falls inside the else end of an if(isGamePad)
// Flip the weapon into the direction it's aiming
if (WeaponIsFacingRight())
{
weaponSprite.flipX = true;
weaponSprite.flipY = false;
}
else
{
weaponSprite.flipX = true;
weaponSprite.flipY = true;
}
// This is where the mouse is in relation to the weapon aim
var pos = Camera.main.WorldToScreenPoint(weaponSlot.transform.position);
var dir = Input.mousePosition - pos;
// Get the x and y aim direction, times by the tick rate and player move speed
float x = dir.x * Time.deltaTime * moveSpeed;
float y = dir.y * Time.deltaTime * moveSpeed;
rads = Mathf.Atan2(y, x);
float degrees = rads * Mathf.Rad2Deg;
weaponSlot.transform.position = new Vector3(weaponPositionX, weaponPositionY, playerPosition.z); // playerPosition;
weaponSlot.transform.localEulerAngles = new Vector3(0, 0, degrees);
And a clip showing the behaviour i’m trying to fix:
I’m sure the solution lays in detecting and action on dir.x dir.y being certain values but i’m struggling to get my head around it based on debugging outputs etc. Any help appreciated!