UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Obtener el ángulo entre dos gameobjects unidos con hinge joint"
using UnityEngine; public class AngleBetweenObjects : MonoBehaviour { public GameObject object1; public GameObject object2; private HingeJoint hingeJoint; void Start() { hingeJoint = object1.GetComponent<HingeJoint>(); } void Update() { float angle = GetAngleBetweenObjects(); Debug.Log("Angle between objects: " + angle); } float GetAngleBetweenObjects() { if (hingeJoint != null) { JointLimits limits = hingeJoint.limits; float angle = hingeJoint.angle; if (angle < limits.min) { angle = limits.min; } else if (angle > limits.max) { angle = limits.max; } return angle; } else { Debug.LogError("HingeJoint not found on object1"); return 0; } } }