Answers for "unity add explosion force"

C#
0

unity add explosion force

public void ApplyExplosionForce()
{
	float explosionForce = 50.0f;
	float affectedRadius = 15.0f;
	
	Collider[] colliders = Physics.OverlapSphere(transform.position, affectedRadius);
    
	foreach (Collider affectedObjects in colliders)
	{
        if (affectedObjects.TryGetComponent(out Rigidbody rigidbody))
	        rigidbody.AddExplosionForce(explosionForce, transform.position, affectedRadius, 1.0f, ForceMode.Impulse);
	}
}
Posted by: Guest on September-15-2021

C# Answers by Framework

Browse Popular Code Answers by Language