Help with contained x axis mouse avoid!

i hope someone can help, i am stuck and i am a fairly mid level actionscripter so this is something i haven’t done before.

i have a little crab movie clip on the bottom of the ocean floor in a scene.
i want the crab clip to avoid the mouse on the x axis only and i want it to be contained to the edges of the movie. i have found info on doing this on both and x and y axis and without being contained. i have also found info on this but without any gravity or friction to it which we need.

any help is much appreciated!


bump> anyone?
please help?

basically, wouldn’t you just make the crab accelerate towards the side of the movie the mouse is farthest from?

Something like this:
if you have a restriction on the crab’s left and right boundaries

var crabMin:Number = 0;
var crabMax:Number = 100;

Then you check the current mouse position, and see whether it’s closer to the left or right.

var currentMouse:Number = _xmouse;
if((crabMax - currentMouse) > currentMouse){ //Meaning the crab is more to the right
// than the left (I think :slight_smile: )
crabMC._x += (.98) * crabMC._x;
} else {
crabMC._x -= (.98) * crabMC._x;

I think that may do it, but I haven’t actually tested that. Oh. and the .98 corresponds to friction. And the reason it’s greater that currentMouse is that crabMin is 0. Otherwise, it’d be a bit different.

If you’re willing to wait a while, I may get around to testing that. Otherwise, ask questions if you have them, and have fun. :slight_smile: