View Full Version : [AS2] Bullets
Why are some of my bullets ( not all of them ) not colliding with a wall and going straight through it ?
DJRoberts
09-28-2009, 10:01 AM
put up your code or flash file.
function checkEnemyHit( object:MovieClip, type ):Void
{
for ( var i = 0; i < bulletArray.length; i++ )
{
var tempBullet:MovieClip = bulletArray[i];
if ( tempBullet.hitTest( object ) )
{
tempBullet.removeMovieClip();
object.health -= 10;
trace( "hes dead" );
}
if ( type != undefined && type == "wall" )
{
if ( tempBullet.hitTest( object ) )
{
tempBullet.removeMovieClip();
}
}
}
}
if ( type != undefined && type == "wall" ) is the start of the wall collision bit
and then in the level code ( my levels are array based so they a created dynamically )
blockHolder['Block'+i].onEnterFrame = function()
{
if ( this.hitTest( player_mc._x-(player_mc._width/2), player_mc._y, true ) && Key.isDown(Key.LEFT) ) {
player_mc._x = player_mc._x + 2;
blockHolder._x = blockHolder._x - 2;
}
else if ( this.hitTest( player_mc._x+(player_mc._width/2), player_mc._y, true ) && Key.isDown(Key.RIGHT) ) {
player_mc._x = player_mc._x - 2;
blockHolder._x = blockHolder._x + 2;
}
else if ( this.hitTest( player_mc._x, player_mc._y-(player_mc._width/2), true ) && Key.isDown(Key.UP) ) {
player_mc._y = player_mc._y + 2;
blockHolder._y = blockHolder._y - 2;
}
else if ( this.hitTest( player_mc._x, player_mc._y+(player_mc._width/2), true ) && Key.isDown(Key.DOWN) ) {
player_mc._y = player_mc._y - 2;
blockHolder._y = blockHolder._y + 2;
}
checkEnemyHit( this, "wall" );
}
The black writing is what calls it so each block on the level is constantly looping the checkEnemyHit(); function so i dont see why the bullets go through..
Wow i worked it out. Thanks for trying though :P
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.