GameObject "jumps" through collision objects

Hello,

I have an issue with my unit gameobjects “jumping” through collision gameobjects (iso tiles) that I have setup with matter physics…

I have included a video showing what this looks like.

My unit is setup like so:

	unitSprite = this.scene.matter.add.gameObject(this, { shape: 'circle', circleRadius: 15} );	
	unitSprite.setCollisionCategory(groundunits);
	unitSprite.setCollidesWith([ground, groundunits]);
	unitSprite.ignoreGravity = true;
	unitSprite.setBounce(0);
	unitSprite.displayWidth = 30;
	unitSprite.displayHeight = 30;
	unitSprite.scale = 0.4;
	var circle = new Phaser.Geom.Circle(150, 150, 40);
	unitSprite.setInteractive(circle, Phaser.Geom.Circle.Contains);

My groups are like so:

	tileGroup = this.add.group();
	dontWalk = this.add.group();
	
	ground = this.matter.world.nextCategory();
	groundunits = this.matter.world.nextCategory();

    tileGroup.setImmovable = true;
    dontWalk.setImmovable = true;

And each tile as it is drawn is done so like so:

            //THE ISOMETRIC POLY SHAPE
			var tile = new Phaser.Geom.Point(i,j);

			const tx = (j - i) * tileWidthHalf
			const ty = (j + i) * tileHeightHalf
			
			const isotopleftX = centerX + tx + tileWidthHalf;  //TOP OF DIAMOND
			const isotopleftY = centerY + ty - tileHeight; //TOP OF DIAMOND
			const isotoprightX = centerX + tx + tileWidth; //RIGHT OF DIAMOND
			const isotoprightY = centerY + ty - tileHeightHalf; //RIGHT OF DIAMOND
			const isobottomleftX = centerX + tx; //LEFT OF DIAMOND
			const isobottomleftY = centerY + ty - tileHeightHalf; //LEFT OF DIAMOND
			const isobottomrightX = centerX + tx + tileWidthHalf; //BOTTOM OF DIAMOND
			const isobottomrightY = centerY + ty + 1; //BOTTOM OF DIAMOND
				
			const iso = isotopleftX + ' ' + isotopleftY + ' ' + isotoprightX + ' ' + isotoprightY + ' ' + isobottomrightX + ' ' + isobottomrightY + ' ' + isobottomleftX + ' ' + isobottomleftY;

//WATER (NON-WALKABLE TILE)
if (tileType==0)
{
            thisTile = this.matter.add.sprite(centerX + tx, centerY + ty, 'flatsprite', 5, { shape: { type: 'fromVerts', verts: iso, flagInternal: true } }).setStatic(true)
			thisTile.depth = centerY + ty;
			thisTile.tileX = i;
			thisTile.tileY = j;
			dontWalk.add(thisTile);
			thisTile.setInteractive();
			thisTile.setCollisionCategory(ground);
			thisTile.setCollidesWith([groundunits]);
			thisTile.body.enable = true; 
			thisTile.body.immovable = true;
}

Am I missing something here? Why is the unit jumping through the tiles?

badcollisions.mkv (1.3 MB)

http://astralforge.net

Hard to tell. It could be your pathfinding positioning. When you position two colliding object atop of one another, the resulting separation will look like a jump.

No real pathfinding is in use here, just a simple tween motion, if that makes a difference. Are you saying the tiles overlapping at all my be causing this?

I dont think its the overlap. I tried shrinking the tile iso by 10 so there are no overlaps, and the issue persists… Video included here to demonstrate what I did:
badcollisionssmaller.mkv (827.7 KB)

I have no idea what I’m looking at :slight_smile: Maybe turn on some collision debugging, so the shapes are visible.
One thing to note though, if you use tweens, there is no velocity, and therefore no correct collision handling…
And even if there was, I’m not sure how you expect your object to get around the obstacle without pathfinding…

I had disabled any pathfinding for working out this bug, i’ll get to that once I figure out proper collisions… I think you’re right, the issue is that it is a tween and no velocity associated. is there a matter physics equivalent to ‘moveTo’ in arcade physics that I can use to accomplish something that includes velocity?

I don’t know, but you can copy the arcade code, which is trivial:

var angle = Math.atan2(y - gameObject.y, x - gameObject.x);
speed = DistanceBetween(gameObject.x, gameObject.y, x, y) / (maxTime / 1000);
gameObject.body.velocity.setToPolar(angle, speed);

(use the actual code, this is just the relevant stuff)

hm, i’m not a Samme or a Davey but if its a tween its possible that it will just plot the coordinates and conflict with the world physics as you say. If you turn on debug gfx you can see the collision boxes that might give a hint. Tweens probably will just set the attribute over time no matter what regardless of what it encounters. All these things happening a-sync (after a fashion) might make it difficult to entangle