In my game there is the player and this player has a sword.
This sword rotates following the mouse cursor, that is, the sword only rotates 360 degrees following the mouse.
But when this sword touches somewhere that has collided with the isTrigger OFF, it ends up changing the position values and ending up being crooked and even far from the player.
I was wondering, how could I fix this problem.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lamina : MonoBehaviour
{
public bool pivotLamina = true;
public float dano;
void Update()
{
if(pivotLamina == true)
{
Vector2 dir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
transform.rotation = rotation;
}
}
}
Thank you very much in advance.