x


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

more ▼

asked Jun 30 '11 at 08:17 PM

BobbleHead gravatar image

BobbleHead
189 29 48 61

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
  }
}
more ▼

answered Jun 30 '11 at 08:45 PM

benni05 gravatar image

benni05
331 2 3 11

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2985
x56

asked: Jun 30 '11 at 08:17 PM

Seen: 2409 times

Last Updated: Jun 30 '11 at 08:45 PM