Home > database >  Sphere Collider, not pushing things when size is changed
Sphere Collider, not pushing things when size is changed

Time:10-27

So I'm trying to make a little pushback effect in my tests arena, I've got a sphere collider and here is my script:

// PushBack Class Script
    if (Input.GetKeyDown(KeyCode.Q))
    { 
        explosion_ball.transform.position = transform.position;
        StartCoroutine(WaitAndPrint());
    }

    IEnumerator WaitAndPrint()
    {
        float i = 0;
        while (i < 1)
        {
            i  = 0.01f;
            explosion_ball.radius = curve.Evaluate(i) * 10;
            yield return new WaitForSeconds(0.01f);
        }
    }
    //__________//

Sphere collider is set and stuff, but it doesn't push things back like I thought it would.

Thanks!

CodePudding user response:

  1. You need to scale up the collider on the object by radius and all the objects it is supposed to wobble need to have Rigid body component attached to them

2.if you ARE doing above things and its not adding any force you could just add a force on all the overlapping objects using the "OnCollisionEnterTrigger" and AddForceMethod radially away from the Sphere Obstacle.position - Sphere.position is the vector Radially away from Sphere I think.

You don't need coroutines for this I think.

CodePudding user response:

I don't know your curve and what values that evaluation produces, but you can check your code visually with Window/Analysis/Physics Debugger, or write a gizmo:

private void OnDrawGizmos()
{
    Gizmos.color = new(1.0f, 0.0f, 0.0f, 0.5f);
    Gizmos.DrawSphere(explosion_ball.transform.position, explosion_ball.radius);
}

Or simply just use https://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html

  • Related