Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For some reason, this simple simple loop is totally broken. (characterSheet is my character Class, it's just a movieClip with some extra functionality) (hitBox, is basically a square movieclip)

Anyway: every time hitBox make contact with a characterSheet in a different order than they were created: Nothing happens. The program only seems to be listening to collisions that are made with o2[0]. As soon as another hitBox is created, it pushes the last one out of o2[0] and the last one becomes totally useless. What's super weird is that I can hit characterSheets in any order I like....

    public function collisions(o1:Array, o2:Array)
    {
        if((o1.lenght>=0)&&(o2.length>=0)){
            for (var i = 0; i < o1.length; i++)
            {
                var ob1 = o1[i];
                for (var f = 0; f < o1.length; f++)
                {
                    var ob2 = o2[f];

                    if (ob1 is characterSheet)
                    {   if (ob2.hitTestObject(ob1))
                            {
                                var right:Boolean = true;
                                if (ob1.x < hitBox(ob2).origin.x)
                                    right = false;
                                characterSheet(ob1).specialDamage(hitBox(ob2).damageType, hitBox(ob2).damage, right);
                                }}}}}}

Also it might be somewhat helpful to see the function for creating a new hitBox

    public function SpawnHitBox(targeted, following, atype, xoff, yoff, ... args)
    {
        var newHitBox = new hitBox(targeted, following, atype, xoff, yoff, args);
        badCollisionObjects.push(newHitBox);
        arraydictionary[newHitBox] = badCollisionObjects;
        addChild(newHitBox);

    }
share|improve this question

closed as too localized by Byte56, Josh Petrie, bummzack, Anko, Trevor Powell Apr 13 '13 at 0:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Should it be for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only –  Samaursa Apr 5 '12 at 2:18
    
HAHA! Stupid mistake, wasted half the day trying to fix it, thanks...Edit:Didn't fix the problem. Though I did find a solution that works for some reason: I have just made it so that when hitBox's are done resizing-animating etc.. They fly 9000 pixels off screen and patiently wait to be collected until the badCollisionObjects.length>=10 when they are spliced. –  Zee Bashew Apr 5 '12 at 2:34
    
;), in that case, I'll put that as the answer –  Samaursa Apr 5 '12 at 2:36

1 Answer 1

I think it should be: for (var f = 0; f < o2.length; f++)... just skimmed the code, that seemed to stand out. If there is only one object in o1 array, then you will get a single collision only

share|improve this answer
    
As I just put up in an edit:this was a problem in the code, but unfortunately It didn't fix the entire problem. Thanks so much though. –  Zee Bashew Apr 5 '12 at 2:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.