Recent posts by ArcticClaws on Kongregate

Flag Post

Topic: Game Programming / HitTest With Rotation and New Direction

Thanks a lot Draco – it works! I’ve been thinking about switching over to AS3 for a while now, as there seems to be a lot of benefits. I might start trying to learn some of it soon. Thanks once again! :D

Once small typo though, if anyone else ever wants to use this code, the line, near the bottom, speedx = 2; should be speedy = 2;.

 
Flag Post

Topic: Game Programming / HitTest With Rotation and New Direction

Hey guys! I’m using AS2 and I’m having a bit of a problem with my code. This is my situation, I have two squares on my stage, let’s call them square 1 and square 2. Square 1 moves. I want square 1 to collide with square 2 and square 1 should rotate on the hitTest and then move in a new direction (either up or down the y-axis or left or right on the x-axis) during and after the hitTest. This is my current code:

onClipEvent (load) {
this._y = 100;
this._x = -100;
speedx = 2;
speedy = 2;
}
onClipEvent (enterFrame) {
	this._x += speedx;
	if(this.hitTest(_root.enemy)){
		_rotation = 45;
		this._y += speedy;
		speedx = 0;
	}
}

Basically, the code says that during a hitTest, the movieclip that this code is attached to rotates 45 degrees and move down the y-axis. The x-axis movement is stopped.

The hitTest and rotation works fine, but I’m not sure how to make it move in a new direction after the hitTest. Currently, square 1 does move during the hitTest, but stops after the hitTest. I want the new direction to continue even after the hitTest is concluded. Does anyone know how to do this? Any help would be appreciated!