UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Obtener el ángulo entre dos gameobjects ,con un gameobject vacío como pivote"
using UnityEngine; public class AngleBetweenObjects : MonoBehaviour { public GameObject object1; public GameObject object2; public GameObject pivot; // Update is called once per frame void Update() { float angle = GetAngleBetweenObjects(object1, object2, pivot); Debug.Log("Angle between objects: " + angle); } float GetAngleBetweenObjects(GameObject obj1, GameObject obj2, GameObject pivotObj) { Vector3 direction1 = (obj1.transform.position - pivotObj.transform.position).normalized; Vector3 direction2 = (obj2.transform.position - pivotObj.transform.position).normalized; float angle = Vector3.Angle(direction1, direction2); return angle; } }