# Advanced random movement - smooth

**URL:** https://forum.kirupa.com/t/advanced-random-movement-smooth/29872
**Category:** Uncategorized
**Created:** [September 1, 2003, 10:55am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872 "2003-09-01T10:55:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mlk](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mlk](https://forum.kirupa.com/u/mlk)
#### Post date: [September 1, 2003, 10:55am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/1 "2003-09-01T10:55:48Z")

</div>

Let me explain - on my upcoming website (in a year, maybe?) i’ll have some sort of cartoon character walking above my contents - and I want his charcter to be smooth _and_ actionscripted. However his movements should be done as a curved motion path would, but random.

Now random movement will either: a) get you to one point and then to the other, but making a sharp turn or b) have no coordination in movement (good for making a bee fly but not for anything else)

here’s what im trying to do:

transform straight lines movement (random):  
 ![](http://forum.kirupa.com/uploads/kirupa/326/ffe7dbc53ffade80.jpg)

to something smoother  
 ![](http://forum.kirupa.com/uploads/kirupa/327/affb200630d5b71c.jpg)

something inside me tells me it’s got something to do with cos and sin functions but I’ve no idea how to make that work.  
And I don’t want to do motion path because I need to do actions that rule that out.

thanks to anyone who could give me a hint =)

---

<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: [September 1, 2003, 10:59am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/2 "2003-09-01T10:59:59Z")

</div>

Maybe you could try using curveTo ? I don’t know, I never actually used it before.

---

<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: [September 1, 2003, 11:53am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/3 "2003-09-01T11:53:55Z")

</div>

Before when I tried to move an MC randomlly I was so stiff. I added a little bounce script and it smoothens the transistion from one random \_x and \_y position. I don’t know if it can be applied to your project though!

---

<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: [September 1, 2003, 2:35pm UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/4 "2003-09-01T14:35:15Z")

</div>

I have actually tackled something like this before.

Using curveTo, and knowlege about bezier curves, you can to pretty much exactly what you’ve talked about.

The trick is in knowing that when you connect, say, 3 points (so, 2 lines) with curveTo, the lines from the anchor points (3) to the control points (2) need to have the same slope. Hmm, this is hard to describe, and I can’t draw you a picture from this comp.

Ok, picture 3 points, in a row, horizontally.

Then you have curveTo anchor points (2 of them) spaced between these 3 dots. So, in order, it’s anchor, control point, anchor, control point, anchor. Let’s label them:

A: 1st anchor  
B: 1st control point  
C: 2nd anchor  
D: 2nd control point  
E: 3rd anchor

Now to make curves that match up, you need to make sure that the slope from B to C is the same as that from C to D.

You are going to do the same thing with these random points. Every time you add a new anchor, you will know where the new control point needs to be (because it must be inline with the last control point, and the last anchor).

This is a lot easier to explain with diagrams, but you prolly get the idea. I’ll draw it when I have the chance.

---

<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: [September 1, 2003, 2:39pm UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/5 "2003-09-01T14:39:04Z")

</div>

Dang, I just re-read your post - you want to move along those lines. Well, you can prolly use the same idea, like, using curveTo lines as guides or something?

Otherwise, you can use 2-point bezier curve equations to guide your MC from point to point.

I know those eqs are around here somewhere…

---

<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: [September 1, 2003, 3:26pm UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/6 "2003-09-01T15:26:23Z")

</div>

How would you tell a movieClip to follow a line movieClip as a guide? Is that possible?

---

<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: [September 2, 2003, 12:05am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/7 "2003-09-02T00:05:22Z")

</div>

I don’t think that’s possible. What should be possible is working out the EQs for the curves, and using those to guide the MC.

Another option might be giving the MC inertia - that way when you give it a new point to head towards, it does’nt just jerk over there, it kind of eases it’s path toward the next point.

---

<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: [September 2, 2003, 1:03am UTC](https://forum.kirupa.com/t/advanced-random-movement-smooth/29872/8 "2003-09-02T01:03:46Z")

</div>

I didn’t think so…bummer. Here’s something you could play with:

```auto

onClipEvent(load){
	_x=610;
	_y=75;
	angle=0;
	radius=random(35);
	ycenter=67;
	speed=5;
	
}
onClipEvent(enterFrame){
	_x-=5;
	_y=Math.sin(angle*Math.PI/180)*radius+ycenter;
	angle+=speed;
if(this._x<20){
this._x = 610;
}
}

```

Then you could add an easing to \_x because the \_x just starts at 610 and moves to the left. The \_y doesn’t have a destination in that formula, but it may be a fraction of what you’re looking for. I added an if statement so it will loop. Put this on a movieClip on a stage that’s 650 pixels wide.
