using UnityEngine; public class HoldableObject : MonoBehaviour { public Transform holder; public Vector3 holdingPosition; public Vector3 holdingRotation; public Vector3 holdingUpRotation; [HideInInspector] public Rigidbody rig; [HideInInspector] public Transform leftHandPos; [HideInInspector] public Transform rightHandPos; [HideInInspector] public PID pid; [HideInInspector] public Vector2 swingAngles; public float swingSpring; public Vector2 twistAngles; public float twistSpring; public bool isHeld; private DragHandler dragHandler; public LayerMask mask; private void Awake() { pid = GetComponent(); rig = GetComponent(); RightHandPos componentInChildren = GetComponentInChildren(); if ((bool)componentInChildren) { rightHandPos = componentInChildren.transform; } LeftHandPos componentInChildren2 = GetComponentInChildren(); if ((bool)componentInChildren2) { leftHandPos = componentInChildren2.transform; } dragHandler = GetComponent(); mask = LayerMask.GetMask("Map"); } private void Update() { if (isHeld) { dragHandler.dragAmount = 1f; } else { dragHandler.dragAmount = 0f; } } private void FixedUpdate() { if (!isHeld) { Hover(); } } private void Hover() { RaycastHit hitInfo = default(RaycastHit); Ray ray = new Ray(base.transform.position, Vector3.down); Physics.Raycast(ray, out hitInfo, 1.5f, mask); Vector3 vector = new Vector3(0f, 0f, 0f); vector.y = 1f - hitInfo.distance; rig.velocity = Vector3.Lerp(rig.velocity, vector * 2f, Time.fixedDeltaTime * 100f); rig.angularVelocity = Vector3.Lerp(rig.angularVelocity, Vector3.up * 5f, Time.deltaTime * 100f); } }