Be a Supporter!

Actionscript hit test help!

  • 339 Views
  • 4 Replies
New Topic Respond to this Topic
ICYCREWPRODUCTIONS
ICYCREWPRODUCTIONS
  • Member since: Aug. 16, 2007
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Actionscript hit test help! 2009-12-09 09:13:50 Reply

So I've began trying to expand my knowledge of actionscript ( I barerely know all the basic stuff)
but I figured that if I downloaded scripts and looked at them, I would much easily get the principles of hit tests.
I was very wrong.

To the real subject, I am making a test game, to experiment with different techniques and such.
I am trying to do this:
When the "players"s (a movie clip, containing frames like a "walk" animation and a "punch animation") punch movieclip collides with the "enemy" movieclip.
I want the "enemy" (movieclip with 2 frames, the second one being the death animation)
How can I pull this off?

I for some reason arranged so that the code applies to the player, even though it's written on the enemy mc.

onClipEvent (enterFrame) {}
if (_root.playerpunch.hitTest(this.enemyhit)) {
		
			_root.gotoAndPlay(2);
		
	}

I really have little knowledge of what I'm doing, so if I'm totally off, I would really appreciate any sort of help!

Thanks!


Icycrew
Yeah, I'm not such a big fan of random "original" banners or sentences...
ICYCREW.COM

grafik2d
grafik2d
  • Member since: Jun. 29, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Actionscript hit test help! 2009-12-09 10:06:28 Reply

the problem come from the fact that you are referencing your ennemy in relative with "this" so the script will look for a movie clip inside your hero's movie clip. Use _root. instead and it should be fine. hitTest() in itself is a very easy function eithe you test for an object (mc.hitTest(otherMc)) or a point mc.hitTest(otherMc._x,otherMc._y,true). For more info about collision detection look for a thread called As:Main or get a book on action script like flash 8 action script bible(hightly recommended)

grafik2d
grafik2d
  • Member since: Jun. 29, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Actionscript hit test help! 2009-12-09 10:09:17 Reply

althought for what you are doing I would sugest to look for the distance and position(crouching,jumping,behind the hero, etc.) of the ennemy.

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Actionscript hit test help! 2009-12-09 14:38:10 Reply

i would strongly recomend trying to understand how the AS is compiled, as it will give you a massive insight on what will work and what wont. Dont just learn that i have to use this. here and _root there etc...

Basically, think of the stage as another movieclip.
to refer to the stage you use _root
inside _root is all your graphics and movieclips and buttons
for example, if you had a movieclip with instance name player on your _root he's target will be _root.player.
the . seperates each instance and the final dot access that instance's properties (which can also be thought of as children of that movieclip)

saying this. obviousally means you are refering to the instance the this. is placed on
so if you had the movieclip with target _root.player. saying this on it will be the same as saying _root.player

if inside your player you had another movieclip, called animation for example its target will be _root.player.animation
get the idea?
also, gotoAndStop() sends a function (thus the () after it, which is the sytax for a function) that sets the target its refering to (before its .) to whatever you put as the parameter inside the gotoAndStop()
eg _root.player.gotoAndStop(5) sends the player to frame 5

hope that helped


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
ICYCREWPRODUCTIONS
ICYCREWPRODUCTIONS
  • Member since: Aug. 16, 2007
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Actionscript hit test help! 2009-12-10 07:00:14 Reply

At 12/9/09 02:38 PM, Yambanshee wrote: hope that helped

Yes! Thank you!
Thanks everyone, I got it to work! :)


Icycrew
Yeah, I'm not such a big fan of random "original" banners or sentences...
ICYCREW.COM