Advanced random movement - smooth

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

to something smoother

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 =)

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

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!

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.

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…

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

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.

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


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.