Odd movement problem

I’ve got this mc that moves left and right when the arrows are pressed, and what i need to do is that once the mc gets to a certain position, it will gotoAndPlay an animation within it.

I tried using hitTest to begin with, but that wasnt working. Am i doing it the easy way of not using hitTest?

Here’s the fla


onEnterFrame = function() {
if(movieClip._x == theXYouWantToTestHere && movieClip._y == theYYouwantToTestHere) {
movieClip.gotoAndPlay(3820);
}
}

Replace movieClip with the instance name of your movieClip, and theXYouWantToTestHere and theYYouWantToTestHere with the X and Y positions of where you want to see if the movieClip is hitting

Put this on the frame of the movie (not the movieClip itself)

thanks for the quick reply :thumb:

I tried out what you suggested, and it looked as if it would work, but, sadly, it didn’t.
Did you try out the code you just gave me on my fla, and if so, did it work for you?

Really? no ideas at all?

Pleaes take a look at my fla on the first post, and see what the problem is?

Thank you

i’m getting kind of sad here…:frowning:

I’ guess i’ll ask one more time…if anyone can take a look at my fla and see waht they can do, thanks.

John

Put this code in a frame (remove the code on your mc’s)

var speed = 5;
blob.onEnterFrame = function() {
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
		this.gotoAndStop("right");
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
		this.gotoAndStop("left");
	}
	if (this.hitTest(tree)) {
		this.gotoAndPlay("anim");
		delete this.onEnterFrame;
	}
};

scotty(-:

hooray!

Thanks for helping me out scotty :slight_smile:
I was beginning to give up on this thing, heh.

Thanks again :thumb:

welcome:thumb:

Hi again, scotty!

Can you point me in the direction of how to create simple left and right boundries for my blob?

** Thanks **


var speed = 5;
blob.onEnterFrame = function() {
if(this._x > 15 && this._x < 150){
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
		this.gotoAndStop("right");
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
		this.gotoAndStop("left");
	}
	if (this.hitTest(tree)) {
		this.gotoAndPlay("anim");
		delete this.onEnterFrame;
	}
}
}

justa suggestion :wink:

Prophet.

hm…well with that, the character just stops abruptly at that x value, and can’t be moved again :frowning:

I’ll keep working on it

oh yeah… dint think it thru entirely… :S sorry!
this works…

var speed = 5;
 var min = -5
 var max=150
 blob.onEnterFrame = function() {
     if(this._x>=max){
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed;
             this.gotoAndStop("left");
         }
     }
     else if(this._x<=min){
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed;
             this.gotoAndStop("right");
         } 
     }
     else{
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed;
             this.gotoAndStop("right");
         } 
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed;
             this.gotoAndStop("left");
         }
     }
     if (this.hitTest(tree)) {
         this.gotoAndPlay("anim");
         delete this.onEnterFrame;
     }
 }

or you could use a slightly shorterhand:

var speed = 5
 var min = -5
 var max=150
 var right = true
 var left = true
 blob.onEnterFrame = function() {
     if(this._x>=max){
         right = false
         left = true
     }
     if(this._x<=min){
         left = false
         right = true
     }
     if(right == true){
         if (Key.isDown(Key.RIGHT)) {
             this._x += speed
             this.gotoAndStop("right")
         } 
     }
     if(left == true){
         if (Key.isDown(Key.LEFT)) {
             this._x -= speed
             this.gotoAndStop("left")
         }
     }
     if (this.hitTest(tree)) {
         this.gotoAndPlay("anim")
         delete this.onEnterFrame
     }
 }

or im waiting for someone to swoop in and use an even better method :frowning: lol

but i hav an excuse atm - iv got a headache (cue sympathy… or lack of…) lol ciao4now!

Prophet.

EDIT:- btw u thinking of easing that movement or leaving it be?