I am working on a side-scroller 2D platformer game. I want to program the player's shield to rotate around the player in the direction of the mouse. For example, if the mouse is above the player, the shield is above too, if the mouse is to the left of the player, the shield is to the left too. I have already made it so the shield is pointing towards the player at all times.
If you don't understand something please ask.
`void Start()
{
mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
void FixedUpdate()
{
mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
Vector3 rotation = mousePos - transform.position;
float rotZ = Mathf.Atan2(rotation.y, rotation.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0, rotZ - 90);
transform.RotateAround(rotateAround.transform.position, Vector3.forward, mousePos.x);
}`