# Moving mc's randomly

**URL:** <https://forum.kirupa.com/t/moving-mcs-randomly/15361>\
**Category:** Uncategorized\
**Created:** [March 13, 2003, 11:56am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361 "2003-03-13T11:56:44Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 12:49pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/21 "2003-03-19T12:49:48Z")

</div>

actually it works **schling** 🙂  
i was like _what the … !!? it should work!_ and tested it 😉

by the way … i’ll fix my script later and i’m not stressed out about it 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:06pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/22 "2003-03-19T13:06:14Z")

</div>

thanks kax

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:08pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/23 "2003-03-19T13:08:57Z")

</div>

> _originally posted by **david** _  
> thanks kax

ehmm … yeah. i don’t know why but you’re welcome =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:35pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/24 "2003-03-19T13:35:59Z")

</div>

Well, I won’t even start to guess why it wouldn’t work on my script. Since most of the codes are the same on both. Exept that you don’t have any code on the mc, just an instance name.

But! Yours work, and I can use it. Just wish I could really understand why mine didn’t work. Guess I must take a good look at it.

Thanks Kax, and to all others that have tried to help me 🙂 I’ll post url for my page as soon as it’s done.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:39pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/25 "2003-03-19T13:39:26Z")

</div>

“I don’t know why but your’e welcome.”

because you saved me the trouble of thinking about the code of course. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:40pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/26 "2003-03-19T13:40:07Z")

</div>

> Exept that you don’t have any code on the mc, just an instance name.

at the end of the code

```auto
mc.onEnterFrame = move;

```

it’s the same than

```auto
onClipEvent (enterFrame) {
	this.move();
}

```

> But! Yours work, and I can use it. Just wish I could really understand why mine didn’t work. Guess I must take a good look at it.

can you post the exact code you used? i might find what’s wrong with it 😉

and again … no problem schling =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 19, 2003, 1:44pm UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/27 "2003-03-19T13:44:56Z")

</div>

> because you saved me the trouble of thinking about the code of course 🙂

oh i see … =)

i should get paid for this 😛 [size=1]jk ;)[/size]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 9:27am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/28 "2003-03-20T09:27:03Z")

</div>

Here it is.

This is my modified code, with your input.  
Don’t know why it won’t work, perhaps it even will at your computer.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 9:42am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/29 "2003-03-20T09:42:49Z")

</div>

mine …

```auto
MovieClip.prototype.move = function() {
	if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
		this.x += this.diffx;
		this.y += this.diffy;
		this._rotation = Math.atan2(this.diffy, this.diffx)*180/Math.PI;
	} else {
		this.x = this.targx;
		this.y = this.targy;
		if (!this.t) {
			this.t = getTimer();
		}
		if (getTimer()-this.t>1000) {
			this.reset();
			this.t = 0;
		}
	}
	this._x = this.x;
	this._y = this.y;
};

```

yours …

```auto
MovieClip.prototype.move = function() {
	if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
		this.x += this.diffx;
		this.y += this.diffy;
		this._rotation = Math.atan2(this.diffy, this.diffx)*180/Math.PI;
	} else {
		this.x = this.targx;
		this.y = this.targy;
		if (!this.t) {
			this.t = getTimer();
		}
		if (getTimer()-this.t>1000) {
			this.reset();
			this.t = 0;
		}
	}
	**this._rotation = Math.atan2(this.x, this.y)*360/Math.PI;**
	this._x = this.x;
	this._y = this.y;
};

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 9:46am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/30 "2003-03-20T09:46:35Z")

</div>

Ops 🙂

what the hell does that line there?  
So, THAT is why mine didn’t work.

You see I had the same line you used before, just at the wrong place. That is what I find really annoying. But now my script is all messy…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 9:52am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/31 "2003-03-20T09:52:32Z")

</div>

you can have the line there if you want to … it shouldn’t be a problem 🙂  
just remove the other line 😉

by the way … i just realize that your line is wrong :-\

```auto
this._rotation = Math.atan2(this.x, this.y) ***360** /Math.PI;

```

shoul be **180** not 360 …

but i can fix that 😉

```auto
this._rotation = Math.atan2(this.diffy, this.diffx)*360/(Math.PI*2);

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 9:57am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/32 "2003-03-20T09:57:47Z")

</div>

Yup, used 180 myself at first, but when it didn’t work I tried to use 360. Since I thought that it would go 360 degrees, while 180 it would only go half the way in the circel.

But as I said, my old script was filled with mess. Guess I scripted it do death :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 20, 2003, 10:02am UTC](https://forum.kirupa.com/t/moving-mcs-randomly/15361/33 "2003-03-20T10:02:10Z")

</div>

> But as I said, my old script was filled with mess. Guess I scripted it do death :-\

😛 … don’t worry, it happens to everyone 😉

[Previous page](https://forum.kirupa.com/t/moving-mcs-randomly/15361.md?page=1)
