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(); } } }
void DropItem() { Player = null; PlayerRigidBody = null; ThisRigidbody.useGravity = true; ThisRigidbody.ResetInertiaTensor(); ThisRigidbody.constraints = RigidbodyConstraints.None; DropTimer.StartTimer(PickupDelay, 1, PickUpReset); }
void UpdateHeldItemPosition() { LocationToMoveTo = Player.transform.position + (Player.transform.forward.normalized * HoverDistance); if (CanMove()) { ThisRigidbody.MovePosition(Vector3.MoveTowards(transform.position, LocationToMoveTo, Time.deltaTime * HoverSpeed)); } var newRotation = Player.transform.rotation.eulerAngles; newRotation.x = StartingOrientation.eulerAngles.x; newRotation.z = StartingOrientation.eulerAngles.y; ThisRigidbody.MoveRotation(Quaternion.Euler(newRotation)); }
/// <summary> /// Дать задний ход. /// </summary> public void MoveBackTank() { ThisRigidbody.AddRelativeForce(Vector3.right * SpeedBack); }
/// <summary> /// Повернуть танк направо. /// </summary> public void TurnRightTank() { ThisRigidbody.AddTorque(new Vector3(0, SpeedTurn, 0)); }
/// <summary> /// Сдвинуть танк вперед. /// </summary> public void MoveForwardTank() { ThisRigidbody.AddRelativeForce(Vector3.right * -SpeedForward); }