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 Kinematic on impact. To stop something colliding remove its collider (assuming Kinematic).
– meat5000I just want to use above code for my specific project. How can I make it work? I got a error doing it.
– kfidanci