Unexpected Collision Detection Results

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Are the testOverlap and testOverlapSolid methods of the IWorldInstance class meant to return true when collision polygon edges are touching, but not actually overlapping?

    For clarity, here is a visual example and the related code I used for testing:

    runOnStartup(async runtime => {
    	runtime.addEventListener('beforeprojectstart', () => {
    		const sprites = runtime.objects.Sprite.getAllInstances();
    
    		const hasOverlap = sprites[0].testOverlap(sprites[1]);
    		console.log(hasOverlap); // true
    
    		const hasOverlapSolid = sprites[0].testOverlapSolid();
    		console.log(hasOverlapSolid !== null); // true (with Solid behavior)
    
    		// AABB sanity check.
    		const hasOverlapAABB = testOverlapAABB(sprites[0], sprites[1]);
    		console.log(hasOverlapAABB); // false
    	});
    });
    
    /*
     AABB (Axis-Aligned Bounding Box) collision detection checks if two instances overlap
     by comparing their edges along both the x and y axes. If the edges overlap on both axes,
     a collision is detected. Collisions must be enabled, though collision shapes are ignored.
     */
    function testOverlapAABB(a: IWorldInstance, b: IWorldInstance): boolean {
    	if (!a.isCollisionEnabled || !b.isCollisionEnabled) return false;
    
    	return a.x < b.x + b.width
    		&& b.x < a.x + a.width
    		&& a.y < b.y + b.height
    		&& b.y < a.y + a.height;
    }
    

    If this is the intended behavior of the aforementioned methods, would a request for a forward-compatible update be worth filing on GitHub? Perhaps the last argument of each method could optionally indicate if touching edges are ignored: a.testOverlap(b, false) and a.testOverlapSolid(false).

    For what it's worth, it looks like Godot, GDevelop, and others may have similar solutions, though touching edges are ignored by default.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On further testing, this appears present as far back as r418, so I'm assuming it's intentional. A short note in the docs would help since it's not the default in many popular engines and there's currently no opt‑out for it.

  • Yeah it’s been like that since Construct 2 first came out. It was noticed and asked about as I recall but it wasn’t changed. It would be something to find that post though.

    The difference only really matters for shapes placed perfectly on a grid at least. And mostly is just an issue with rectangle shapes. I tend to shrink the collision poly slightly, or shrink the size slightly, or do my own aabb collision check if it matters.

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