View Full Version : Hit test problems
scags
May 12th, 2005, 01:54 PM
I decided to do a basic game, just for fun. Programming the whole thing took me barely any time, but once i had it going i realized i had a problem. I need to do a hit test for a movie clip inside another movie clip. The game is a timing game, jumping over hurdles, but it is seen from above. I basically need a way to detect if the player is touching the hurdle in the first and last frames few frames of the jump animation.
unchew
May 12th, 2005, 02:04 PM
place the "if hitTest bla bla bla" on the last and first frame of your animation, checking if the _root.hurdle is hitting it.
scags
May 13th, 2005, 04:10 PM
I don't know what is wrong now but here is the swf and the code. I would rather not give the fla if it can be avoided.
This is the code for the part when the player can hit the hurdle:
onClipEvent(load){
speed = 3;
}
onClipEvent(enterFrame){
_root.hurdles._x-= speed;
if (_root.hurdles.hitTest(getBounds(_root.player).xMa x, _root.player._y, true)) {
_root.gotoAndStop( 4 );
}
if (_root.hurdles.hitTest(getBounds(_root.player).xMi n, _root.player._y, true)) {
_root.gotoAndStop( 4 );
}
if (_root.hurdles.hitTest(_root.player._x, getBounds(_root.player).yMax, true)) {
_root.gotoAndStop( 4 );
}
if (_root.hurdles.hitTest(_root.player._x, getBounds(_root.player).yMin, true)) {
_root.gotoAndStop( 4 );
}
if(_root.hurdles._x == -30){
_root.hurdles._x = 220;
}
}
this is for the part where the player is in mid air:
onClipEvent(load){
speed = 3;
}
onClipEvent(enterFrame){
_root.hurdles._x-= speed;
if(_root.hurdles._x == -30){
_root.hurdles._x = 220;
}
}
I am not sure if the ground code works, but I am pretty sure it should.
Edit: The seperated code doesn't show up on my mac, but shows up on windows computers. Is there something I can do about this?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.