# GameObject "jumps" through collision objects

**URL:** <https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677>\
**Category:** Phaser 3\
**Created:** [May 26, 2021, 11:14pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677 "2021-05-26T23:14:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dustin\_Rogers](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dustin_rogers/32/5261_2.png) [@Dustin\_Rogers](https://phaser.discourse.group/u/Dustin_Rogers)\
**Post date:** [May 26, 2021, 11:14pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/1 "2021-05-26T23:14:07Z")

</div>

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](https://phaser.discourse.group/uploads/short-url/diA9nX1zn2thCieMUklFvonuiya.mkv) (1.3 MB)

[http://astralforge.net](http://astralforge.net)

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [May 27, 2021, 8:40am UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/2 "2021-05-27T08:40:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dustin\_Rogers](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dustin_rogers/32/5261_2.png) [@Dustin\_Rogers](https://phaser.discourse.group/u/Dustin_Rogers)\
**Post date:** [May 27, 2021, 6:49pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/3 "2021-05-27T18:49:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dustin\_Rogers](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dustin_rogers/32/5261_2.png) [@Dustin\_Rogers](https://phaser.discourse.group/u/Dustin_Rogers)\
**Post date:** [May 27, 2021, 6:55pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/4 "2021-05-27T18:55:07Z")

</div>

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](https://phaser.discourse.group/uploads/short-url/hnxlX3FtDJLvQEH6IhBlw62CS5E.mkv) (827.7 KB)

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [May 27, 2021, 7:16pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/5 "2021-05-27T19:16:21Z")

</div>

I have no idea what I’m looking at 🙂 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…

---

<div class="post-metadata">

**Author:** ![Dustin\_Rogers](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dustin_rogers/32/5261_2.png) [@Dustin\_Rogers](https://phaser.discourse.group/u/Dustin_Rogers)\
**Post date:** [May 27, 2021, 7:58pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/6 "2021-05-27T19:58:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [May 27, 2021, 8:26pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/7 "2021-05-27T20:26:06Z")

</div>

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

```javascript
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](https://github.com/photonstorm/phaser/tree/v3.51.0/src/physics/arcade/ArcadePhysics.js#L515) code, this is just the relevant stuff)

---

<div class="post-metadata">

**Author:** ![rudyardcatling](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rudyardcatling](https://phaser.discourse.group/u/rudyardcatling)\
**Post date:** [May 30, 2021, 7:15pm UTC](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/8 "2021-05-30T19:15:17Z")

</div>

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
