Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Stick to surface?

Discussion in 'Editor & General Support' started by elias723, Mar 31, 2006.

  1. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    How do I make an object stick to another one when they collide? (ie sticky grenades, mines, "oddjob hat" sticking to where it hits a person) I assume that it is something to do with Physic Surfaces, but because I'm not too experienced in that area, I would appreciate any help anyone can lend me.
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I took a screenshot of a physic material which is sticky. You should be able to attach that to a grenade.

    You should probably also make the collision sphere larger otherwise the collider will penetrate.


    Another solution would be to add forces along the normal of the surface you are colliding with from inside the OnCollisionStay function.
     

    Attached Files:

  3. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Ok, I tried the physic material, and without it, the grenade acts fine (but doesn't stick, of course). With it, it will go through any material it hits, no matter the size of the collider. I'm not exactly clear on what you are suggesting for the adding forces bit: do you mean add force to the sphere to hold it where it is?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Actually an interesting idea with those sticky grenades. Couldn't resist trying it out.

    See the attached script.

    The script presumes that you will attach it to a projectile which also has a rigidbody attached.

    When hitting rigidbodies it will connect itself with a fixed joint.
    When hitting other colliders or the character controller it will follow it by modifying the transform.position to always maintain the same offset to the sticked to surface.

    I am sure there are simpler ways to do it but this is probably the most robust way to handle it.
     

    Attached Files:

  5. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Sweet! The script works great. Thanks again for the help.
     
  6. Grune

    Grune

    Joined:
    Nov 8, 2009
    Posts:
    136
    It' been up a while but i found it today and made good use of it.

    Thanks for the script.

    I'll try to ad a remote detonate funktion