barbeaulex
07-13-2009, 08:49 PM
Hey everyone ! I'm trying to develop a game like Ronin : Spirit of the Sword (for the combat part anyway) and I'm having trouble with the hit detection. Please note that the game is still in very early stages. Here is my code for the sword swinging (actions are on the first frame in the timeline)
onMouseDown = function () {
createEmptyMovieClip("Line", 1);
Line.lineStyle(1, 0x000000, 100);
Line.moveTo(_xmouse, _ymouse);
};
onMouseUp = function () {
Line.lineTo(_xmouse, _ymouse);
};
As for the enemies, here is the code (actions are on the movieclip)
onClipEvent (enterFrame) {
if (this.hitTest(_root.Line)){
this.unloadMovie();
}
}
It seems to work fine, but seeing as how the sword slash is loaded in an empty movie clip, the hit zone isn't just the line, it is a rectangle starting from the mouse down going to the mouse up. So even if the line doesn't touch the enemy, if the empty part of the clip overlaps with an enemy, the hit registers. Is there any way to fix this ?
Thanks a bunch !
onMouseDown = function () {
createEmptyMovieClip("Line", 1);
Line.lineStyle(1, 0x000000, 100);
Line.moveTo(_xmouse, _ymouse);
};
onMouseUp = function () {
Line.lineTo(_xmouse, _ymouse);
};
As for the enemies, here is the code (actions are on the movieclip)
onClipEvent (enterFrame) {
if (this.hitTest(_root.Line)){
this.unloadMovie();
}
}
It seems to work fine, but seeing as how the sword slash is loaded in an empty movie clip, the hit zone isn't just the line, it is a rectangle starting from the mouse down going to the mouse up. So even if the line doesn't touch the enemy, if the empty part of the clip overlaps with an enemy, the hit registers. Is there any way to fix this ?
Thanks a bunch !