Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
Enemy don not follow Player. Phaser3

Can you please tell me where I made mistake in code ? why my enemy do not follow player? I am not sure if I defined correct followPlayer() . 'SceneB' is second Scene, can be this problem ? Console.log is clear . I am using EasyStar.js library. Game is working , everything is running but enemy is frozen .
Thank you


 class SceneB extends Phaser.Scene {
    constructor(){
      super('SceneB')
    }
   //..


create(){

finder = new EasyStar.js()
    let grid = []
    let tile 
    for(let y = 0; y < map.height; y++) {
         let col = []
      for(let x = 0; x < map.width; x++) {
         tile = map.getTileAt( x, y )
         col.push( tile.index)
      }
      grid.push(col)
    }

    finder.setGrid(grid)
  
    let tileset = map.tilesets[0]
    let properties = tileset.tileProperties
    let acceptableTiles = []

    for (let i = tileset.firsgid - 1;i < tiles.total;i++) {
       if(properties[i].collides == false ) {
         acceptableTiles.push ( i+1)
       }
    }

       finder.setAcceptableTiles( acceptableTiles) 

}


update(){}

followPlayer(player,evil) {
      

      let toX = this.player.x
      let toY = this.player.y

      let fromX = this.evil.x
      let fromY = this.evil.y

      finder.findPath(fromX, fromY, toX, toY, function(path) {
         console.log(path)
         this.moveCharacter(path)
       })

       finder.calculate()
    }


      moveCharacter(path){
        let mytimeline = this.scene.tweens.createTimeLine()    

        for(let i = 0;i < path.length - 1;i++) {
          let ex = path[i + 1].x
          let ey = path[e + 1].y

            mytimeline.add({
             targets: this.player,
            x:{value: ex * map.tileWidth, duration: 200},
            y:{value: ey * map.tileHeight, duration: 200}
          })
        }
        mytimeline.play()
      }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

followPlayer is never getting called, so the logic will never actually trigger.

You'll want to call this somewhere in your code, depending upon how you've implemented your player logic.

You may also want to check inside finder.findPath that path !== null, and do something if it is, as that could also cause an issue.

finder.findPath(fromX, fromY, toX, toY, function(path) {
 console.log(path);
 if (path !== null) {
     this.moveCharacter(path);
 }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda