/* * Triggers animation of knife returning to player */ public void ReturnKnifeTransition() { // this is a lot of return :O if (returning) { return; } // reset knife collision variables (in case it was stuck to something) returning = true; objectStuck = null; stuckInSurface = false; gravPanel = null; transform.SetParent(null); this.PostNotification(ShowKnifeMarkerNotification, null); StartCoroutine("ReturnKnifeAnimation"); }
/* * Sticks knife into surface when colliding with an object */ public virtual void StickToSurface(Vector3 _position, Vector3 _normal, GameObject _other, bool _cancelNotifications = false) { // disable rigidbody rb.isKinematic = true; dontGoThroughThings.enabled = false; stuckInSurface = true; // align knife position with collision position transform.position = _position; transform.rotation = Quaternion.FromToRotation(Vector3.up, _normal); // stick knife out of surface at collision point rb.velocity = Vector3.zero; // parent knife to other gameobject (to handle moving objects) transform.SetParent(_other.transform); objectStuck = _other; if (_cancelNotifications) { trailRenderer.enabled = false; return; } KnifeInteractionTrigger knifeTrigger = objectStuck.GetComponent <KnifeInteractionTrigger>(); if (knifeTrigger != null) { // disable autoWarp autoWarp = false; // attach knife to interactable object knifeTrigger.AttachKnife(); } GravityPanel tempGravPanel = objectStuck.GetComponent <GravityPanel>(); if (tempGravPanel != null) { // Prepare to shift gravity if warping to GravityPanel gravPanel = tempGravPanel; gravShiftVector = gravPanel.GetGravityVector(); if (gravShiftVector == Vector3.zero) { gravShiftVector = -_normal; } } Controller controller = objectStuck.GetComponent <Controller>(); if (controller != null) { //autoWarp = true; // TODO: store controller for switching after warp this.PostNotification(ReturnKnifeNotification); this.PostNotification(Controller.ControllerChangeNotification, controller); return; } FibreOpticController fibreController = objectStuck.GetComponent <FibreOpticController>(); if (fibreController != null) { // Activate fibre optic warp this.PostNotification(FibreOpticWarpNotification, fibreController); return; } // activate knife marker ui Info <Transform, bool> info = new Info <Transform, bool>(transform, gravPanel != null); this.PostNotification(ShowKnifeMarkerNotification, info); }