Weapon following mouse and orbiting Player

Hello!, i didnt really know how to explain my problem in the title, so i’ll address some pictures :

I Currently have this :
(Dont pay attention to the sprites, i do not have access to the originals right now :$)
The sword rotates to follow my mouse position, everything ok.
57258-spr2.png

But this just seems nice if if pointing in front of my character, if the weapon goes up, it feels like it lacks reach and does not look good :frowning:

What i would like to achieve is something like this :
57260-spr3.png

The weapon still points to the mouse position, BUT!, the pivot point follows along the red line, to give the illusion of…having arms.
I think it basically works by finding the closest point on that red line to the mouse position, and the sword moves that way.

Thank you beforehand.

You could try rotating in a circle around your character with something like this script attached to the sword:

// Point you want to have sword rotate around
public Transform shoulder;

// how far you want the sword to be from point
public float armLength = 1f;

void Start() {
	// if the sword is child object, this is the transform of the character (or shoulder)
	shoulder = transform.parent.transform;
}

void Update() {

	// Get the direction between the shoulder and mouse (aka the target position)
	Vector3 shoulderToMouseDir = 
		Camera.main.ScreenToWorldPoint(Input.mousePosition) - shoulder.position;
	shoulderToMouseDir.z = 0; // zero z axis since we are using 2d

	// we normalize the new direction so you can make it the arm's length
	// then we add it to the shoulder's position
	transform.position = shoulder.position + (armLength * shoulderToMouseDir.normalized);
}

Hope this gets you started! You should be able to find ways to clamp your sword to a certain arc if you don’t want it to do 360’s around your character. There is also transform.RotateAround you could look into.