// Called by the InteractionSystem when an interaction starts private void OnStart(FullBodyBipedEffector effectorType, InteractionObject interactionObject) { if (effectorType != FullBodyBipedEffector.LeftHand) { return; } // Rotate the pivot of the hand targets by 90 degrees so we could grab the box from any direction // Get the flat direction towards the character Vector3 characterDirection = (interactionSystem.transform.position - pivot.position).normalized; characterDirection.y = 0f; // Convert the direction to local space of the box Vector3 characterDirectionLocal = box.transform.InverseTransformDirection(characterDirection); // QuaTools.GetAxis returns a 90 degree ortographic axis for any direction Vector3 axis = QuaTools.GetAxis(characterDirectionLocal); Vector3 upAxis = QuaTools.GetAxis(box.transform.InverseTransformDirection(interactionSystem.transform.up)); // Rotate towards axis and upAxis pivot.localRotation = Quaternion.LookRotation(axis, upAxis); // Rotate the hold point so it matches the current rotation of the box boxHoldPoint.rotation = box.transform.rotation; }
protected override void RotatePivot() { Vector3 normalized = (this.pivot.position - this.interactionSystem.transform.position).normalized; normalized.y = 0f; Vector3 v = this.obj.transform.InverseTransformDirection(normalized); Vector3 axis = QuaTools.GetAxis(v); Vector3 axis2 = QuaTools.GetAxis(this.obj.transform.InverseTransformDirection(this.interactionSystem.transform.up)); this.pivot.localRotation = Quaternion.LookRotation(axis, axis2); }
// Rotate the pivot of the hand targets by 90 degrees so we could grab the object from any direction protected override void RotatePivot() { // Get the flat direction towards the character Vector3 characterDirection = (pivot.position - interactionSystem.transform.position).normalized; characterDirection.y = 0f; // Convert the direction to local space of the object Vector3 characterDirectionLocal = obj.transform.InverseTransformDirection(characterDirection); // QuaTools.GetAxis returns a 90 degree ortographic axis for any direction Vector3 axis = QuaTools.GetAxis(characterDirectionLocal); Vector3 upAxis = QuaTools.GetAxis(obj.transform.InverseTransformDirection(interactionSystem.transform.up)); // Rotate towards axis and upAxis pivot.localRotation = Quaternion.LookRotation(axis, upAxis); }