- Home /
How do I “freeze” an object after a collision?
How do I “freeze” an object after a collision? I have a spear that is being instantiated and has velocity toward a target. When it hits the target I want it to stay stuck into the target and stay there without being dislodged by other spears. (I guess I want to deactivate / hide / remove the spears collider after it hits??). The reason I want to hide the spears collider is that if the next spear hits the same spot it’s going to knock the first one over.
Also the spear is a rigidbody, so when I’m setting transform vector 3 to 0,0,0 the object isn’t sticking in to the target, it stops moving forward but it is still slowly falling to the ground. I’ve used this code and put this on the original spear object:
function OnCollisionEnter(hit : Collision){
if(hit.gameObject.tag=="myTarget"){
transform.Translate(Vector3(0,0,0));//stop cloned spear moving
transform.Rotate(Vector3(0,0,0));//stop cloned spear rotating
rigidbody.useGravity = false; //stop it falling to ground
print("You hit the target");
}
}
Any help to "freeze" and then isolate an object after a collision with a target would be greatly appreciated.
Cheers Chris
Ok this is old but it resurfaced to page 1 so Im adding my 2p.
To freeze an object (rigidbody) I would make it $$anonymous$$inematic on impact. To stop something colliding remove its collider (assu$$anonymous$$g $$anonymous$$inematic).
I just want to use above code for my specific project. How can I make it work? I got a error doing it.
Answer by henry96 · Aug 17, 2011 at 04:49 AM
I think u should make an empty object which has box collider and set it to trigger. Then, parent ur spear to that empty object. After that, u write some codes that if the new spear trigger the empty gameobject. Then remove the old spear. Hope this help!
Hi Henry96, thanks for the response. What I have has worked once I clicked on the trigger check box. I needed to do that so it stopped the other physics collisions on the spears. It has developed a lag in the collisions on the target now though, but I think that's going to be a different issue. Thanks again. Cheers Chris
Answer by em2 · Aug 17, 2011 at 04:23 AM
I found part of the answer here: http://answers.unity3d.com/questions/150203/pause-gameobject-motion.html
The second part was, how to handle collisions with other spears hitting the one already stuck in the target??
Answer by alla_it93 · Feb 16, 2016 at 12:59 PM
use Is kinmatic property -> rigid body to freeze the spear once hit the target
Your answer
Follow this Question
Related Questions
Collision in between 2 objects moving away from each other? 1 Answer
Allow picked up object to collide with game level GameObjects 1 Answer
How to make player collide with ground? 1 Answer
Objects rotating after falling on another object with Physics & Gravity? 1 Answer
Falling object on collision 0 Answers