Changin the VelocityY upon collision

I don’t know how to change the VelocityY on collision with something. Here is the preload function:

function preload() {
this.load.atlas('player', 'assets/spritesheet.png', 'assets/sprites.json');
this.load.image('blobby', 'assets/blobby.png');

now for the update function because the create function isn’t necessary to understand the context

function update() {
//This thing here is where I put key binds for the regular jumping key
if(this.keyUp.isDown && this.player.body.is.touching.down){
this.player.setVelocityY(-400);
this.anims.play("jump"); //this is the animation so ignore it
}
//now below that I want to make it so that when the player touches blobby, their velocity is changed
if(/*code for if the player is touching blobby*/){
this.player.setVelocityY(-550);
}

Your help is very much appreciated :slight_smile:
Thank you!

If you really want to see the create function:

this.keyUp = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
this.blobby = this.physics.add.staticGroup();

I don’t believe this is valid: this.player.body.is.touching.down

Phaser bodies don’t have an is property. I think you might be looking for https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html#touching__anchor

2 Likes

I still don’t understand what to do

I need someone to tell me what code to put in the parenthesis in the update function

Your code right now is: this.player.body.is.touching.down

I’m saying that body.is doesn’t exist. Instead, body.touching does, and is a javascript object that looks like https://photonstorm.github.io/phaser3-docs/Phaser.Types.Physics.Arcade.html#.ArcadeBodyCollision

So you should be able to do body.touching.down, based on that API documentation.