Side collision detection

Hello everyone,
I’m trying to make the player collide with the platform. At the start, the player will be at the center and a platform appears from the left side. The player has to jump and land on the platform which works perfectly. But if the player doesn’t jump, then the platform should collide with the player and die but that doesn’t happen. The platform comes on top of the player that is shown in the screenshot below. I’m using collider() to check for collision and up, down, right and left property to check at which side the collisions happens.

project link: GitHub - maheshnnaik/phaser3example

Thank you.

Body touching needs a velocity to work. Tweens don’t set velocity.

@Milton Thank you for your reply.
Can you please suggest an alternative method instead of Tweens?
I need platform animation such that it should appear from sides.
Is there a lerp function and can we use that so that collision works?

Thank you

Just don’t use body.touching. The collision registers, Check the direction yourself.

Sorry, but I didn’t get that actually.
Can you give a sample code or example to check for collision direction?

Thank you

In the collider callback check the overlap of the player and the platform. In this case something like (platform.x + platform.width) > player.x. (and y also collides).

Thank you for your reply. I have set the velocity to move block instead of tween and now able to check for side collision.

I wanted to know if there is a way to check collision with the world bounds. Or with setCollideWorldBounds set to true, if we can move the block out of the scene. Like in the previous example, when certain platforms appear I need to move the blocks downwards. I tried this but didn’t work. When I set setCollideWorldBounds to false and allowGravity to false, the platforms falls out of the scene.

I don’t get it. Do you want to collide or not? And why would it fall without gravity?

Yes, I want the collision with the player, and it’s working. What I want is when the second platform appears on top of first, I need to move the platforms downwards a little. Since I have set setCollideWorldBounds to true I cant move it on the y axis. Similar to the game Stack Jump.
Thank you

Nope. Still don’t get it (might be because I’m watching England - Germany :slight_smile: ) . Describe your problem exactly (use a picture), or put it online somewhere.

Thank you for your reply.
This is the project link: GitHub - maheshnnaik/phaser3example

If you keep jumping on the platforms, you keep on moving upwards and reach the top of the screen. What I am trying is after I have jumped on 2 or 3 platforms, I need them to move downwards so that the player is always on screen. I can also move the camera along with the player but it doesn’t work properly.
I couldn’t attach a video of a reference game here so I have added it to Github. You can see that the platforms move downwards.
Thank you

Hmm. nice graphics :slight_smile:

I guess I would use the camera, but you can also just remove the bottom platform (once you’re at a certain height).

Thank you for your reply. Instead of destroying I’m moving all the blocks downwards.
How can I add collision between platforms?
`this.platforms =;

    for(let e = 0; e < 2; e++){
        let platform = new Block({scene: this, 
            x: 0, 
            y: height, 
            key: 'block'}
        height = height - platform.height / 2;

this.physics.add.collider(this.platforms, this.platforms, null,null, this); This doesn’t work.
Thank you

Ah, I thought that video was your game :slight_smile:

Anyway, just use this.physics.add.collider(this.platforms);

No, that was the reference game actually.

link: GitHub - maheshnnaik/phaser3example

I have changed my code but sometimes the collision won’t work properly. Please check this if you time, like play 2-3 times, and each time it behaves differently. I’m not sure which property of the physics body I need to change. I looked different reference but no luck.
Thank you

If things are movable and gravity is high, arcade physics is going to fail. It will push through :slight_smile:
You can play around with OVERLAP_BIAS and TILE_BIAS, but it will never work perfectly.

Looking at your video, you can tell it doesn’t use physics for pushing down the platforms, so use tweens for moving down.

Thank you for the reply.

I will try this and will try using tweens.
What I thought was if I move the ground, then the platforms on the ground will also move with it since the masses are 1 and I enabled the gravity.

I would remove physics as soon as the platform stops (or at least make it immovable). And then tween it as a container (i.e. all platforms are in a container).

I used velocity for the player to jump down instead of only gravity. The gravity on the player was set to 100 maybe that was why arcade was failing sometimes. Now it works fine.
Thank you for the help.