I have been trying to make my weapon rotate around the player based on were the mouse is. Its kina like this:
The closest I could get is rotating the weapon in place and not around the player I put the weapon as a child of the player and put this script in the weapon. Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackArea : MonoBehaviour
{
void Update()
{
Vector2 dir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle - 10, Vector3.forward);
transform.rotation = rotation;
}
}
I would be thankful for your help!