Skip to main content
Participating Frequently
November 3, 2012
Answered

Simple Collision Detection in ActionScript 2?

  • November 3, 2012
  • 1 reply
  • 2850 views

I am trying to make a simple maze game, but the collision detection is not working. I have the player moving with the arrow keys, and I am trying to make it so that when the player collides with the wall, it goes to a certain frame. I have this code in the wall movie clip:

onClipEvent (enterFrame) {

if (_root.player.hitTest(this))

{

gotoAndStop("death");

}

}

The player's instance name is "player" and the wall's instance name is "walls1". When the player hits the wall, the player just goes right through it. I'm pretty sure it's something with the collision, not the "gotoAndStop("death");" because I tested it with "gotoAndStop(5);" and the player still goes through the wall.

If someone could help me, I would really appreciate it. Thanks in advance!

This topic has been closed for replies.
Correct answer Ned Murphy

What object are you expecting to goto frame 5 ("death")?

You should move your code to the main timeline and target the objects.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
November 3, 2012

What object are you expecting to goto frame 5 ("death")?

You should move your code to the main timeline and target the objects.

CJ_C1Author
Participating Frequently
November 3, 2012

Thank you so much! The problem was it was trying to go to frame 5 in the object, not the timeline.

Ned Murphy
Legend
November 3, 2012

You're welcome