Stretching collider collision detection

I would like to have a stretchable object that can collide with other objects. This stretchy object will be attached to another object on a fixed jointed, such that moving the fixed object will whip the stretchy object around. Collisions with this stretchy object should cause it to reverse spin around the fixed object.

Video for context and clarification (skip to ~1:00):

Bottom line: Particle cloud should be physical.

I am not entirely sure how to go about rigging up something like that.

My first thought was to position a collider object halfway between the orbitals and rotate it properly… but I can’t detect any sort of physical interaction this way because it’s being manually updated instead of by the physics engine.

Second thought was to use a PID to have it chase a target set by the orbital controller. It would be moving physically and could detect collisions, but since the stretchy collider is still separate from the orbitals, I will have to capture any detected collisions and relay forces to the orbital that’s not being held. That means determining which orbital is not currently being held (maybe neither, maybe both!), doing some fancy mathemagics, and updating their velocities.
I have not attempted this yet. It’s a very intimidating undertaking, to be entirely honest. In fact, I am mostly curious if anyone has dealt with a scenario like this and might have some pointers or insight to share?
[EDIT] A thought just occurred to me that it may not even pick up collisions due to the fact that I’d be updating the collider constantly to adjust scale. :frowning: (Guess I should test that part first…)[/EDIT]

It’s like… I want to make the stretchy collider and the orbitals part of the same object so they all rotate around the fixed joint the same, but the orbitals have to be separate in order to function.

Um, so, yeah, that’s it… Any takers? :smile:
I’ll be posting updates if I make any notable progress on my own.

I think I’ve found the solution. The stretching actually doesn’t seem to interfere with the collision detection :smile:
Had that not worked, my backup plan was to only update the collider’s scale every Nth frame and shoot for something that didn’t fail often enough to be noticeable. But I’m glad it didn’t come to that, lol

It is as I described above. I have the stretchy collider PID controlled, chasing a target set by the orbitals. When the collider detects collision, it will apply the impulse correction to the orbitals that are not being held.

void OnCollisionEnter(Collision col)
    {
        updateOrbitalVelocity(col.impulse);
    }

    void OnCollisionStay(Collision col)
    {
        updateOrbitalVelocity(col.impulse);
    }

    private void updateOrbitalVelocity(Vector3 impulse)
    { 
        // Update physical orbitals with impulse velocity
        foreach (Rigidbody rig in physicalOrbitalRigs)
        {
            if (rig)  // Since this is a list item, it may have nullified at some point
                rig.velocity += impulse / Time.fixedDeltaTime;
        }
    }

Note we have to update during both OnCollisionEnter as well as OnCollisionStay. By placing it into OnCollisionStay, we can have it apply force for as long as the collision remains active.

While the collider doesn’t necessarily always bounce back like some kind of awesome light sabre duel, it does effectively deflect the blow! The collision causes the orbital to slow at an alarming rate which makes it retract from spring force. During a full-on bounce back, the effect is as I envisioned where the orbital takes an almost 180 and swings back around from the opposite direction. I’ve tested this with fairly thin capsule colliders ~0.1 units thick (Interpolate, Continuous Dynamic). Also, this is effected by physics materials! So giving the stretchy colliders extra bounciness in their materials actually works. :slight_smile: