- Home /
Question is off-topic or not relevant
How to get Vector3 of force that WILL BE applied to Rigidbody with AddForce()?
(sorry for poor english)
I have rigidbody that have RigidbodyConstraints.FreezeAll and external force (in my case its ExplosionForce) that i need to accumulate on this rigidbody and apply when RigidbodyConstraints is None. I have script that freezes, save velocities of all rigidbodies in defined radius on key press and unfreezes, applies saved velocities on other key. I need to add this accumulated external force as Vector3 to saved initial velocity of rigidbody. Please help!
Also you can suggest your own ways to made TimeStop mechanic!
Code of rigidbody freezing:
private void TimeStop()
{
Collider[] colliders = Physics.OverlapSphere(transform.position, abilityRadius, rbMask);
foreach (Collider nearbyObj in colliders)
{
Rigidbody rb = nearbyObj.GetComponent<Rigidbody>();
if (rb != null)
{
rbVelocity.Add(rb.velocity);
rbAngularVelocity.Add(rb.angularVelocity);
rbList.Add(rb);
rb.constraints = RigidbodyConstraints.FreezeAll;
}
}
}
private void TimeResume()
{
foreach (Rigidbody rb in rbList)
{
rb.constraints = RigidbodyConstraints.None;
rb.velocity = rbVelocity[0];
rbVelocity.RemoveAt(0);
rb.angularVelocity = rbAngularVelocity[0];
rbAngularVelocity.RemoveAt(0);
}
rbList.Clear();
}
Scheme of my idea:
Follow this Question
Related Questions
AddForce to the Left? 3 Answers
Using rigidbody.AddForce and speeding the object 2 Answers
About Forces and Time.deltaTime 3 Answers
How do I add diagonal force? 0 Answers
C# script not working 1 Answer