system
1
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
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!
system
2
I found part of the answer here:
The second part was, how to handle collisions with other spears hitting the one already stuck in the target??
use Is kinmatic property → rigid body to freeze the spear once hit the target