PDA

View Full Version : [AS2] Collision with the wrong object


NANNERS
01-26-2011, 03:00 AM
I have my player named "Player" and a little square named "Feet" at its feet. They are both Movie Clips.
I have a simple box named "Crate" and a simple floor named "Ground".
Way back when I used to have it do collision with the Player itself, which worked fine. Then I swapped out the line that said "Player" in the collision check with "Feet", but it continues to use "Player".


TouchingGround = false; // Used by my gravity code, if false, player will fall
for(i in _root)
{
if(typeof(_root[i])=="movieclip") // Yes they're all movie clips
{
if (_root[i].ofType == "GROUND") // Each object I want collision with has this variable applied to it
{
if (_root[i]._name <> "Player") // Because the feet are always touching the player
{
if (_root.Feet, hitTest(_root[i])) // If the feet are colliding with any one of these objects
{
TouchingGround = true; // Disable falling with my gravity function
}
}
}
}
}


I've quadruple checked names and made absolutely sure everything has the right variable. In fact I can place whatever I want where "_root.Feet" is (like "hfksalhfklsa") and the code compiles just fine and continues to use the player as colliding check. If I delete the TouchingGround = true; then I will fall forever, so it is actually accepting the code.
Does anyone have any idea what's going on? I can't see any reason it won't use my Feet movie clip. It only ever uses the Player movie clip for collision.

NANNERS
01-26-2011, 03:08 AM
I really hate it when I do this.
It happens every time. I post a question and then I figure it out a minute later, even though I'd been spending the past couple of hours trying to figure it out. Now my question is "why is it this way?"
I took that code that was on the Player movie clip and placed it on the Feet movie clip, and suddenly it worked. it's as if it didn't matter what I wrote as the first part, it just did collision with the object it's placed on. There I go again. I guess I figured it out just asking. Well if anyone has the same problem, there's your answer.

rrh
01-26-2011, 01:16 PM
if (_root.Feet, hitTest(_root[i]))
Is that supposed to be a comma, or a period. ?