private void FixedUpdate() { if (Player == null) { return; } if (Input.GetButtonDown("Interact") && CanBeDropped) { DropItem(); } else if (Input.GetButtonUp("Throw") && CanBeDropped) { var playerVelocity = Player.GetComponentInParent <Rigidbody>().velocity; var baseThrowForce = Mathf.Lerp(ThrowForceMin, ThrowForceMax, (float)ThrowTimer.Elapsed.TotalSeconds / TimerToMaxThrow); var throwingVelocity = Player.transform.forward * Mathf.Clamp(baseThrowForce, ThrowForceMin, ThrowForceMax); DropItem(); ThrowTimer.Stop(); Throwing = false; ThisRigidbody.AddForce(throwingVelocity); } else { UpdateHeldItemPosition(); var distance = Mathf.Abs(Vector3.Distance(transform.position, LocationToMoveTo)); if (distance >= StuckDropTollerance) { DropItem(); } } }
// Update is called once per frame void Update() { if (Player == null) { return; } if (Input.GetButtonDown("Throw") && !Throwing) { Throwing = true; ThrowTimer.Reset(); ThrowTimer.Start(); } }