private void DoThrowExecute(PickupInteraction item, HumanoidInventoryController inventory) { if (CanThrow(item)) { inventory.DropItem(item, true); // TODO: The item should know by itself whether it is attached or not // Rigidbody is ensured by CanThrow Rigidbody body = item.GetComponent <Rigidbody>(); body.AddForce(DoThrowGetAngle() * THROW_DISTRACTION_FORCE, ForceMode.Impulse); } }
private bool CanThrow(PickupInteraction item) { // Cannot throw? if (item == null || item.IsHolstered() || !item.IsVisible() || item.GetComponent <Rigidbody>() == null) // Throwing makes sense for physical objects only { Debug.Log("Throw aiming not possible"); return(false); } // TODO: Make a throwable property and check that, too return(true); }
private bool DoThrowAiming(PickupInteraction item) { if (CanThrow(item)) { // Rigidbody is ensured by CanThrow Rigidbody body = item.GetComponent <Rigidbody>(); float mass_item = Mathf.Max(THROW_REFERENCE_MASS, body.mass); Vector3 start = body.position; // Do the trajectory! float v0 = THROW_DISTRACTION_FORCE / mass_item; float time_step = 0.1f; // Simulate every 100ms of flight DrawAimingTrajectory(start, DoThrowGetAngle() * v0, time_step); return(true); } else { return(false); } }