Jump to content

How to make script climb inclined tiled


Hakuchi
 Share

Recommended Posts

I'm using Phaser3 to make arcade game, but I cant make the dog climb that slope(in the image below). What can i do?
Here's my code until now.

create(){
        //Mapa
        this.map = this.make.tilemap({key:"map"});
        this.background=this.add.image(0,0,'background').setOrigin(0,0);
        this.tiles = this.map.addTilesetImage("mainlev_build1","tile_set");
        this.tilesProp = this.map.addTilesetImage("Props","tile_set_props");
        this.layerGround = this.map.createStaticLayer("Map_Ground", [this.tiles,this.tilesProp],0,0);
        this.layerGround.setCollisionByProperty({collides:true});

        //slopes
        //Controles
        this.controls = this.input.keyboard.createCursorKeys();
        this.player = this.physics.add.sprite(32,game.config.height-150,'woof');

        //animations
        this.anims.create({
            key:'left',
            frames: this.anims.generateFrameNumbers('woof', {start: 0, end: 1}),
            frameRate: 10,
            repeat: -1
        });
        this.anims.create({
            key: 'right',
            frames: this.anims.generateFrameNumbers('woof', {start: 2, end: 4}),
            frameRate: 10,
            repeat: -1
        });

        this.anims.create({
            key: 'hold',
            frames: this.anims.generateFrameNumbers('woof', {start: 2, end: 2}),
            frameRate: 10,
            repeat: -1
        });

        //camaras to follow player
        this.cameras.main.setBounds(0, 0, this.map.widthInPixels, this.map.heightInPixels);
        this.cameras.main.startFollow(this.player);
        this.background.setScrollFactor(0);

        //colisoes
        this.layerGround.setCollisionByExclusion([-1]);
        this.physics.add.collider(this.player,this.layerGround);
        this.player.setCollideWorldBounds(true);
        this.physics.world.setBounds(0,0,2400,592);

    }
    update(){
        if (this.controls.left.isDown) {
            this.player.setVelocityX(-160);
            this.player.anims.play('left', true);
        }
        else if (this.controls.right.isDown && this.player.body.blocked.right) {
            this.player.setVelocityX(160);
            this.player.anims.play('right', true);
        }
        else if (this.controls.right.isDown) {
            this.player.setVelocityX(160);
            this.player.anims.play('right', true);
        }
        else {
            this.player.setVelocityX(0);
            this.player.anims.play('hold', true);
        }

        if (this.controls.up.isDown && this.player.body.blocked.down) {
            this.player.setVelocityY(-600);
        }
    }

 

Screenshot_9.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...