/// <summary> /// Smoothly lerps object to a specific distance in front of the player camera. /// </summary> private void Grab() { if (hit.transform.tag == "Metal Object") { objectToGrab = hit.transform.gameObject; Rigidbody objectRigidbody = objectToGrab.GetComponent <Rigidbody> (); Vector3 desiredPosition = playerCamera.transform.position + playerCamera.transform.forward * grabDistance; if (objectToGrab != null) { isGrabbingObject = true; objectRigidbody.useGravity = false; objectRigidbody.isKinematic = false; objectRigidbody.velocity = (desiredPosition - objectToGrab.transform.position) * (grabSpeed * Time.deltaTime); if (!hasSentEvent) { if (PickupObject != null) { PickupObject.Invoke(0); } hasSentEvent = true; } if (grabSound != null && !audioSource.isPlaying) { audioSource.clip = grabSound; audioSource.Play(); } } } }