x


Collision destroyed script on player collision

I'm making a game where an object moves towards you, but when it gets close enough, the objects moving script get's destroyed. How would a script like that be made? Here is the follow script:

var speed : int = 0; var followrange : int; var stoprange : int; static var canmove : boolean = true; var target : Transform; private var stopped : boolean = false;

function Update(){

if(Vector3.Distance(target.position, transform.position) <= followrange && stopped == false) { canmove = false; transform.LookAt(target); transform.Translate(Vector3(0,0,1) * speed * Time.deltaTime); }

if(Vector3.Distance(target.position, transform.position) <= stoprange) { canmove = false; transform.LookAt(target); stopped = true; }

if(Vector3.Distance(target.position, transform.position) > stoprange) { stopped = false; }

if(Vector3.Distance(target.position, transform.position) > followrange) { canmove = true; }

}

more ▼

asked Jul 31 '12 at 01:12 AM

Cbjfan1 gravatar image

Cbjfan1
42 4 17 29

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

1 answer: sort voted first

If you want to destroy the script, you can put

Destroy(this);

where you want the script to be completely removed.

more ▼

answered Jul 31 '12 at 06:40 AM

JChilton gravatar image

JChilton
33 1 1 3

(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:

x3342
x764
x500

asked: Jul 31 '12 at 01:12 AM

Seen: 243 times

Last Updated: Jul 31 '12 at 06:40 AM