PDA

View Full Version : hitTest


Fishinghat
09-06-2004, 03:39 PM
Hi, I'm creating a space game that involves a hitTest, if an asteroid collides into the space ship game over, written the code, tested it, but doesn't seem to work.

Here's my asteroid code:

onClipEvent (load) {
this._y = (Math.random()*320)+3;
rockSpeed = (Math.random()*10)+1;
}

onClipEvent (enterFrame) {
if (this._x<8) {
rockSpeed = 10;
this._x += 10;
}
if (this._x > 530) {
rockSpeed = -10;
}
this._x += rockSpeed;
rotChoice = (Math.random()*2)+1;
if (rotChoice=1) {
this._rotation += 6;
} else if (rotChoice=2) {
this._rotation -= 6;
}
if(this.hitTest(_parent.motherShip)) {
gotoAndPlay("S4", 1);
}

}

curryjon51
09-06-2004, 08:18 PM
Hi

Drew a rock, put your code on it... drew a mothership. Added a trace to the hitTest:

if(this.hitTest(_parent.motherShip)) {
gotoAndPlay("S4", 1);
trace("hit")
}

And your code worked...

So I think the problem is with the gotoAnd Play line. Think it should be:

pathToMyMc.gotoAndPlay("S4", 1);

or something similar.


Hth

Fishinghat
09-07-2004, 12:59 AM
if (this.hitTest(this._parent.motherShip)) {
trace("Hit!");
this._parent.gotoAndStop("S4", 1);
}

what sort of path? tried _root, doesn't work