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.
@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?
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).
Hi,
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.
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 ) . Describe your problem exactly (use a picture), or put it online somewhere.
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
Thank you for your reply. Instead of destroying I’m moving all the blocks downwards.
How can I add collision between platforms?
`this.platforms = this.add.group();
for(let e = 0; e < 2; e++){
let platform = new Block({scene: this,
x: 0,
y: height,
key: 'block'}
);
this.platforms.add(platform);
height = height - platform.height / 2;
this.platformCount++;
}`
this.physics.add.collider(this.platforms, this.platforms, null,null, this); This doesn’t work.
Thank you
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
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.
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.