A
A
Alexander2020-07-25 00:14:27
Unity
Alexander, 2020-07-25 00:14:27

Physical explosion does not affect Rigbody, how to fix it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Explosion : MonoBehaviour
{
    public float radius;
    public float force;

    void Start()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
        foreach(Collider nearbyObject in colliders)
        {
            Rigidbody rb = nearbyObject.GetComponent<Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }
    }
}

This script "hangs" on the explosion (prefab), which spawns on the condition. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zZaKko, 2020-07-25
@AlexandrG44

https://docs.unity3d.com/ScriptReference/Rigidbody...
AddExplosionForce - accepts 4 variables, but you give only 3. Try it as it is on the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question