How disable collisions with other object(s) for some object instances?

0 favourites
  • 6 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi

    I have a box (without cover) and balls inside (with Physics behavior). Balls have boolean instance variable: InBox = true

    I added an invisible sprite on the top of the box. When I rotate a box, balls fall out (on collision with sprite change boolean from true to false).

    Problem:

    I need to disable collisions of Instances (that have instance variable InBox=false) with object family.

    I tried to do it using the Invert InBox condition and action: Disable Physics collision with Family, but it disables all collisions (not only for instances with InBox=false).

    How to disable collisions only for instances with specific instance variables?

    Thank you for any help.

  • Did you try using a for each ball and then if on the InBox variable?

    Just an idea. You can print out line by line in the for each loop to

    get a better handle of what is going on.

  • Did you try using a for each ball and then if on the InBox variable?

    Just an idea. You can print out line by line in the for each loop to

    get a better handle of what is going on.

    I'm a beginner in this stuff and have no experience in programming.

    Do you mean I need to use scripting: instVars and getAllInstances(), addEventListener(type, func, capture)?

    Can I get an example of your idea? Thank you.

  • luke7eco;

    I mean the system condition for each (see documentation). I have never understood when to use it or not but sometimes it fixes my problems. I include part of the documentation below. I don't know if this will help, but it is what I would try.

    For Each is commonly mis-used or used redundantly - actions already apply for each instance picked by conditions, so it often is simply not needed. However, if you fully understand how the event system works, it can be used to force the event to apply once per instance where the event system would not normally do that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Anyway, thank you.

    I think this will work similarly to "Is boolean instance variable set"

    But my problem is more on the Action level, where I can't find options that will allow me to disable collisions for the instance variables. There is the only option to choose an object.

  • I guess in conditions I should choose "Is boolean instance variable set" (InBox) and Invert it (so it will be "false"). This will allow me to pick instances with a specific instance variable.

    In action, I should "Add script" with something like this (because I still need to have enabled collisions with that object (Family) for instances with instance variable InBox=true):

    for (const inst of runtime.objects.Ball.pickedInstances())
    {
    	// here must be a code to disable collision with a specific Physics object (Family in my case)
    }
    

    Ashley I will be grateful for a code snippet that will allow me to disable collision with object Family for picked instances

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