Need a script to stick rigid body to any rigid body it comes into contact with.
Essentially I'm using a kit that has some decent mechanics for weapons and grenades. The physics are wonderful and everything works great, I would just like to be able to create another grenade, but this one will only differ from the original in the sense it will stick to other rigid body objects or other objects with rigid bodies that also have a certain script attached. I understand learning this myself would be best, but I'm just toying around with some things and would really appreciate it if someone could write this or 2 scripts for me as simply as possible. Either one that sticks the object to any rigid body it collides with, or one as I said, that sticks to other objects that also have a certain script attached to them. Thank you in advance!
Answer by $$anonymous$$ · Jul 06, 2018 at 11:53 AM
Perhaps make the grenade child of the object it touches?
for example
public class StickyGrenade : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
this.transform.parent = collision.gameObject.transform;
}
}
Try it and tell me if it works.
Your answer
Follow this Question
Related Questions
How to make physics collisions act like in old games (NES, SNES especially) 1 Answer
Object shakes on collide! 1 Answer
Unity Ball moving inside the surface 0 Answers
Is there any good sample code for shooting a projectile and collision detection? 0 Answers
Moving rigidbody with addforce, velocity or position causes another object not to collide anymore. 0 Answers