I’m having a problem with a movie clip colliding with elements in an array in Actionscript 3. When I specifically define a movie clip to collide with, it works fine. However, once I throw the code in a for loop, it stops working. Here’s what I mean:
This code works for detecting if the player collides with the top of either of 2 movie clips: http://pastebin.com/YkCzrykr
Once I convert the collision code into an array and detect if the player collides with anything inside, it stops working, shown in this code: http://pastebin.com/WeffU8as
What is supposed to happen is the player spawns a bit above the platforms (defined by sldTerrain#) and drops down and stops. This works when I use the crude code, but not when I put the elements into the array. Can anybody help me?
Thank you in advance.
Since you are looping through the array to check everything, if a hit is detected and isGrounded set to true the loop will continue and can find an object that doesn’t hit and it will set isGrounded back to false. Is that what you intended? If not you should just break out of the loop when you set isGrouned to true.