- Home /
Stop moving box when hit other box
Can somebody help me. I like to stop my moving box when it hit de tag "stop"
#pragma strict
function Start(){}
function Update(){}
function OnTriggerEnter(myTrigger : Collider){
if (myTrigger.gameObject.tag == "man"){
transform.Translate(Vector3.left);
}
if (myTrigger.gameObject.tag == "stop"){
Debug.Log("Hello");
}
//transform.Translate (Vector3.zero);
}
Stijn
Answer by Berenger · May 11, 2012 at 04:18 PM
I don't know how your box is moving assuming it's done elsewhere, but this code going to make it jump one unit on it's left when a physic object with the tag "man" is physically moved into colliding with your box.
If your box have a rigidbody and you want to stay still when an object tagged stop hit it, destroy the rigidbody.
Your answer
Follow this Question
Related Questions
[illustrated!] [code!] Stop object's movement when it is close to another one 0 Answers
Starting a new animation, after stopping another. Without transitions. 1 Answer
how to check movement ended? 1 Answer
Stop Character moving immediately 2 Answers
How do I spread a movement over several frames instead of one? 1 Answer