Behavior Help ?

  • I have created a behavior that moves a enemy in a grid and is restricted by solid objects. I would like to make each enemy not overlap each other inside the behavior. Can anybody point me in the right direction to add the functionality to my behavior.

  • So basically i'm asking how do I get the x and y postion of each instance so i can check for overlap?

  • Tried the following code and it gets stuck at cnd.type, it says its null.

    var runtime = this.runtime;
    var cnd = runtime.getCurrentCondition();
    var mytype = cnd.type;
    var mysol = mytype.getCurrentSol();
    var myinstances = mysol.getObjects();
    var mylen, myl;
    var myflag = 0;
    
    for (myl = 0, mylen = myinstances.length; myl < mylen; myl++)
    {
        myinst = myinstances[myl];
        if ( myinst.x == this.inst.x && myinst.y == this.inst.y )
        {
            myflag = 1;
        }
    }
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is the code that solved my problem.

    var mylen, myl;
    var myflag = 0;
    var mytype = this.inst.type;
    var myinstances = mytype.instances;
    
    for (myl = 0, mylen = myinstances.length; myl < mylen; myl++)
    {
        myinst = myinstances[myl];
        if ( myinst.x == this.inst.x && myinst.y == this.inst.y && this.inst.get_iid() != myinst.get_iid() )
        {
            myflag = 1;
        }
    }
    
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)