- Home /
Question by
BobbleHead · Jun 30, 2011 at 08:17 PM ·
camerascrolling
on collision stop transform.translate
As title says, I have a scrolling camera but when camera box collider hits otherobject i'd like it to stop movment, but i'm nto entirely sure how to go about this, any ideas would be great.
var speed : float = 0.5;
function Update () {
transform.Translate(Vector3(0,speed,0) * Time.deltaTime);
}
function OnTriggerEnter(otherObject: Collider){
if(otherObject.gameObject.tag == "cameracollision"){
transform.Translate(Vector3(0,0,0));
}
}
Thank you
Comment
Best Answer
Answer by benni05 · Jun 30, 2011 at 08:45 PM
You would define a flag that prevents the object from moving, i.e. like this:
var speed : float = 0.5;
var shouldMove : boolean = true;
function Update () {
if (shouldMove) {
transform.Translate(Vector3(0,speed,0) * Time.deltaTime);
}
}
function OnTriggerEnter(otherObject: Collider){
if(otherObject.gameObject.tag == "cameracollision"){
transform.Translate(Vector3(0,0,0));
shouldMove = false;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612130338im_/https://answers.unity.com/themes/thub/images/avi.jpg)