Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
El enemigo no sigue al jugador. Phaser3

¿Puedes decirme dónde cometí un error en el código? ¿Por qué mi enemigo no sigue al jugador? No estoy seguro si definí el followPlayer() correcto. 'SceneB' es la segunda escena, ¿puede ser este problema? Console.log está claro. Estoy usando la biblioteca EasyStar.js. El juego funciona, todo funciona, pero el enemigo está congelado.
Gracias

 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 answers
Answer question

0

followPlayer nunca recibe una llamada, por lo que la lógica nunca se activará.

Querrá llamar a esto en algún lugar de su código, dependiendo de cómo haya implementado la lógica de su player .

También puede verificar dentro de finder.findPath esa path !== null , y hacer algo si es así, ya que eso también podría causar un problema.

 finder.findPath(fromX, fromY, toX, toY, function(path) { console.log(path); if (path !== null) { this.moveCharacter(path); } });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!