actionscript collision detection problems

Started by: NinjasRule34 | Replies: 8 | Views: 600

NinjasRule34
2

Posts: 153
Joined: Mar 2008
Rep: 10

View Profile
Jun 6, 2009 1:24 PM #433506
Ok so heres the setup. i have to charecters. when I press the left mouse key he attacks. I need it so when 'player' presses the mouse and there is also a positive collision detection between 'player' and 'Enemy', the enemy will be removed. To let you know i tried this is what i have so far


onClipEvent (mouseDown) {
if(_root.player.hitTest(_root.Enemy)){
removeMovieClip(Enemy);
}
}



And here is the game so far:
http://www.swfcabin.com/open/1244255516

EDIT:

New updated version
http://www.swfcabin.com/open/1244295448
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Jun 6, 2009 1:46 PM #433522
The enemy has to be spawned with script, else you can't remove it with your script.
doc

Posts: 1,127
Joined: Jan 2009
Rep: 10

View Profile
Jun 6, 2009 1:48 PM #433524
What I usually do is put a MC in the player, where his sword is. I make it invisible and give it an instance name of "heroAttack". Then, it the enemy MC, you can put this:

if(this.hitTest(_root.hero.heroAttack)){
this.removeMovieClip();
}

of course you would put it in a handler. And you would have to replace "hero" with the instance name of your player.
NinjasRule34
2

Posts: 153
Joined: Mar 2008
Rep: 10

View Profile
Jun 6, 2009 1:58 PM #433537
Quote from Scorpioxxx
The enemy has to be spawned with script, else you can't remove it with your script.


How do you spawn with script
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
Jun 6, 2009 2:15 PM #433553
DuplicateMovieclip and then there's some other stuff I can't pull off the top of my head, check pirates space game tutorial, it uses the script.
NinjasRule34
2

Posts: 153
Joined: Mar 2008
Rep: 10

View Profile
Jun 6, 2009 2:32 PM #433578
ooo this seems hard. But I understand all of the actionscript i put into my game and i could recreate it at a moments notice, so at least i learned something:D

Time to ditch this project, quit flash for two weeks, remember about stickpage, and make something retarded like this again.
doc

Posts: 1,127
Joined: Jan 2009
Rep: 10

View Profile
Jun 6, 2009 3:10 PM #433626
Oh, not removeMovieClip, but you could use unloadMovie() if you want. Well I guess you're stopping, oh well.
NinjasRule34
2

Posts: 153
Joined: Mar 2008
Rep: 10

View Profile
Jun 6, 2009 5:07 PM #433767
I was joking. I found inspiration
doc

Posts: 1,127
Joined: Jan 2009
Rep: 10

View Profile
Jun 6, 2009 6:33 PM #433834
Oh ok. If you really want to learn to spawn and remove with script, pm me, i may be able to help.