Is object picking 100% reliable?

  • I have to ask. It's probably some kind of bug on my end but I can't find it and it's driving me a bit nuts

    I have a group of object instances (Character) I loop through every game tick. Like this:

    Every loop calls a few functions to handle the current Character's movement, collisions, and rendering:

    I'm passing object UID's to these functions, which is probably bad practice. But they're global objects created on startup and their UID's never change. So it should be okay.

    The problem happens in Collider_Chr(). This function aligns a couple of collision boxes on each side of the Character object and checks if they're overlapping with anything. If one of them does, an instance boolean gets set to true. If there's no overlap, the boolean is false.

    This function is structured the same way basically as everything else in the game: I pass an UID to the function, then pick the Character instance from that passed parameter. And it works fine. Except in this case. This event/function doesn't want to pick the right Character instance for some reason, so all the collider objects get set to the position of the first Character in the main loop.

    I can't figure it out. This 'pick instance by passed function parameter' approach works fine everywhere else, at least as far as I can tell. Anyone able to see what I'm doing wrong here?

  • Try to separate overlapping "or" conditions into separate events. Usually overlapping test won't work correctly with "or" condition.

  • I split them up and it worked! Thanks so much

    That's a pretty mean gotcha. Is the 'or' operator a bit flaky in general maybe?

  • If you separate them, you might have a problem with the 'else'.

    I suppose that 'platform' is a tilemap and 'breakable' a sprite. So you cant bring them in 1 family.

    So, make 'breakable' a tilemap, if possible. Now just check overlap with 1 family. I what i prefer.

    You can separate them like ...

    is overlapping platform

    ____set boolean

    else

    is overlapping breakable

    ____set boolean

    else

    ____unset boolean

    i think that should work

  • I don't know what exactly underneath, but it work just like that for overlapping test. But you can combine overlapping test condition with "and" condition (normal without "or") just fine. "Or" condition is reliable outside from using it for overlapping test.

  • I don't think you need the for each, and you definitely don't need the every tick.

  • I'm passing object UID's to these functions, which is probably bad practice. But they're global objects created on startup and their UID's never change. So it should be okay.

    Here are some tips you might find helpful when trying to pin point problems.

    What you can do is to create a log and use that to track what is going on more closely in the code. Just make a List and call it List_Log or whatever you prefer. Change it from dropdown list to a listbox in the properties menu, then you can use the additem varies places where you think things might go wrong.

    Also there is nothing wrong in passing UID to a function, in fact its very good to do so, because they are unique. Not that there is anything wrong in your picking. But what you can do that might simplify your picking, is to do what I have done above. The red area in my example does exactly the same as in yours. However you don't have to use local variables etc. anyway just a tip.

  • If you separate them, you might have a problem with the 'else'.

    I suppose that 'platform' is a tilemap and 'breakable' a sprite. So you cant bring them in 1 family.

    So, make 'breakable' a tilemap, if possible. Now just check overlap with 1 family. I what i prefer.

    You can separate them like ...

    is overlapping platform

    ____set boolean

    else

    is overlapping breakable

    ____set boolean

    else

    ____unset boolean

    i think that should work

    Yeah no prob, I structured it like this:

    Pick Collider -
                                     | Set C_CannotBePushedRight to False     (defaults to this)
    
       Is overlapping     | Set C_CannotBePushedRight to True
    [/code:86tay4lq]
    
    I did discover that another problem event got cleared up by going from this:
    
    [code:86tay4lq]
    Is ConditionA            | Do stuff
           - or -
    Is ConditionB  
    Else                           | Do something else
    [/code:86tay4lq]
    
    ... to this:
    
    [code:86tay4lq]
    Is ConditionA           | Do stuff
    Is ConditionB          | Do stuff
    Not ConditionA      | Do something else
             - and -
    Not ConditionB
    [/code:86tay4lq]
    
    Not trusting 'or' from now on 
    
    

    nimos:[/p] That's a nice trick, thanks [/p] [/p] newt[/p] Is there a more efficient way to iterate through them? I use a boolean to minimize the looping already (Activated). Every tick, yeh I agree. Lots of game logic that needs updating if I change it but maybe I should anyway.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Perhaps you should use the inverse logic, although it could be a bit slower.

    Not overlapping object A and Not overlapping object B -> Set to False

    Else -> Set to True

  • Other than getting rid of the functions is activated should do fine.

  • Shouldn't the "is activated" go before the foreach loop for efficiency? I thought as is it is now it will loop over every object, whereas is you put the "is activated" first it will pick those first then loop over the picked. May not sound like much but if you have 500 people and only 2 are active, you're searching 2 rather than 500.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)