GetCollisionEngine or .TestOverlapSolid ... is this not part of the official sdk?

0 favourites
  • 7 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I'm really confused.

    I read through the manual for addon sdk several times. I also searched for it as well...

    Every included behavior that moves instances around and deals with collisions involves getting a reference to the CollisionEngine and using it for things like .TestOverlapSolid. I notice the example with the GhostShooter tutorial uses .testoverlap but that also isn't mentioned in the sdk as far as i can find (when I search for it)

    runtime.GetCollisionEngine isn't included in the sdk, but .runtime is. Are we allowed to use it? Why or why not.

    Is this not a part of the official sdk, and if not, how are we "supposed" to go about testing for collisions?

  • I remember using it in my flags behavior but it doesn't seem to be officially supported. (Accessing anything with _ is usually a no-no). I made a suggestion a while ago for it but you know... they take a while if they happen at all.

    construct.net/en/make-games/addons/949/flags/versions

    Here's the code:

    CheckOverlap(flags) {
    			const collisionEngine = this._runtime.GetCollisionEngine();
    			const flagsInstances = this._behInst._behavior._myInstances._arr;
    			let result = false;
    			
    			result = flagsInstances.some(i => {	
    				const t = collisionEngine.TestOverlap(this.GetObjectInstance(), i);
    				if(t) {
    					if (i.GetBehaviorSdkInstanceFromCtor(C3.Behaviors.Wackytoaster_Flags)._HasFlags(flags)) {
    						return true;
    					}
    				}
    			});
    			
    			return result;
    		}

    You'll need to adapt it for your use ofc. I guess the main point is simply

    const collisionEngine = this._runtime.GetCollisionEngine();
    collisionEngine.TestOverlap(instanceA, instanceB);
    
  • In the ghost shooter script, ObjectInstance.TestOverlap(SomeOtherObjectInstance); is used.

    There is no _privateVariable marker there, so I would assume its okay, but again.... it isn't "documented", so technically it isn't. I guesse? Idk?

    There is a code snippet provided at:

    construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventblock

    In the above, _runtime is referenced... Again, no documentation on it, but it is part of an example.

    Honestly, without actual, robust, examples, construct's sdk is kind of an exclusive club. The documentation is poor compared to other software. Seems odd to just list a few methods and functions on a webpage and call it good. Reminds me of getting into shaders. The fact that the built in behaviors can't be used as an example... they use so many "cheats", custom runtime modifications, etc...

    It means authoring plugins is an obscure and esoteric art fraught with unavoidable pitfalls.

  • In the ghost shooter script, ObjectInstance.TestOverlap(SomeOtherObjectInstance); is used.

    here is no _privateVariable marker there, so I would assume its okay, but again.... it isn't "documented", so technically it isn't. I guesse? Idk?

    This is documented actually

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/object-interfaces/iworldinstance

    But iirc it isn't available in the SDK.

    None of these work.

    this.testOverlap()
    this._inst.testOverlap()
    this._inst.GetWorldInfo().testOverlap()
    

    this.runtime is also not available, but rather it's available as this._runtime. However, this._runtime.testOverlap() doesn't work either.

    I haven't done anything SDK in a while, but maybe it's fine to use _vars because it is in the documentation? Maybe I just misremember something. Either way, I cannot find an easy way to test for overlap like it's done in the regular javascript.

    Hence the direct access to the collision engine which as far as I can tell, is undocumented. It's also bad because I think it actually skips most optimizations like collision cells, it's just a raw call of "Is instance X overlapping instance Y"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is documented actually

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/object-interfaces/iworldinstance#internalH1Link3

    But iirc it isn't available in the SDK.

    Gosh dang it, the addon sdk is different than the javascript blocks and assets???!!! So now you have two connections to the c3 runtime that differ?

    Hence the direct access to the collision engine which as far as I can tell, is undocumented. It's also bad because I think it actually skips most optimizations like collision cells, it's just a raw call of "Is instance X overlapping instance Y"

    What makes you think that? all the built in behaviors that call it would suffer but they seem performant enough, regardless of how many solids exist. I mean, I can set up some tests, but it would be absurd to me to have a call that bypassed the optimizations. atoh, If you are specifically testing 1 instance vs another then optimizations aren't going to matter a whole lot anyway (1st check being an aabb, I would think, which is super fast.) I haven't actually looked through this area of the engine since c2 so, this is as all hypothetical conjecture.

  • What makes you think that? all the built in behaviors that call it would suffer but they seem performant enough, regardless of how many solids exist.

    Hmm maybe you're right, but it was something I had in the back of my head. I even mention it being performance heavy on the addon page.

    If you tear open the collision engine you'll see that testOverlapSolid() does:

    TestOverlapSolid(inst) {
     const wi = inst.GetWorldInfo();
     this.GetSolidCollisionCandidates(wi.GetLayer(), wi.GetBoundingBox(), tempCandidates);
     for (const s of tempCandidates) {
     if (!this.IsSolidCollisionAllowed(s, inst)) continue;
     if (this.TestOverlap(inst, s)) {
     C3.clearArray(tempCandidates);
     return s;
     }
     }
     C3.clearArray(tempCandidates);
     return null;
     }

    Calling this.GetSolidCollisionCandidates which eventually down the road does a check with collision cells filtering out unneeded collision candidates.

    GetCollisionCandidates(layer, rtype, bbox, candidates) {
     const isParallaxed = layer ? layer.GetParallaxX() !== 1 || layer.GetParallaxY() !== 1 : false;
     if (rtype.IsFamily())
     for (const memberType of rtype.GetFamilyMembers())
     if (isParallaxed || memberType.IsAnyInstanceParallaxed()) C3.appendArray(candidates, memberType.GetInstances());
     else {
     memberType._UpdateAllCollisionCells();
     memberType._GetCollisionCellGrid().QueryRange(bbox, candidates);
     }
     else if (isParallaxed || rtype.IsAnyInstanceParallaxed()) C3.appendArray(candidates, rtype.GetInstances());
     else {
     rtype._UpdateAllCollisionCells();
     rtype._GetCollisionCellGrid().QueryRange(bbox, candidates);
     }
     }

    Before doing testOverlap().

    Since I'm calling testOverlap() directly I'm skipping the step where I'm filtering out based on collision cells. In my case I'm also testing a custom behavior overlap, so I'm testing overlap against all instances that have my behavior attached. This will do an overlap check for all instances regardless of distance.

    Or at least that's what I assume. It appears that the javascript actually also just calls testOverlap(a,b) so that either means it also does not filter out based on collision cells OR it does and I'm simply mistaken.

    Point is I didn't manage to tap into the this.GetSolidCollisionCandidates function from my addon so I sort of assumed it to be not optimal.

  • Wait... this makes me think the javascript part actually is in fact borked because how do you test for overlap? You HAVE to feed individual instances into testOverlap() meaing if you wanna check 1000 spriteA vs 1000 spriteB you have to use

    const sprite = runtime.objects.Sprite;
    const sprite2 = runtime.objects.Sprite2;
    
    for(const i of sprite.instances()) {
    	for(const i2 of sprite2.instances()) {
    		if(i.testOverlap(i2)) console.log("coll");
    	}
    }

    Or am I mistaken here? Because like this obviously the evenperformance is better by an insane margin

    compared to js

    Am I missing something here?

    EDIT: Lmao nope, even the ghost shooter example has this issue. The event version has like ~6k collision checks at most where the js version quickly balloons to 20k when shooting. I guess this one is actually worth filing a bug for?

    EDIT2: Nevermind I guess github.com/Scirra/Construct-bugs/issues/5665 :V

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