Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
How do I make a sprite chase another sprite in javascript?

Im making a game where I need the enemy to spot the player once in a certain range, and then start chasing the player. I cant find anything anywhere at all that would help with how to make sprites chase each other

Im using Kaboom.js, javascript only (no html), on replit.com

Here is my code so far but it does not work because to my knowledge Kaboom.js does not have a way to get only the x position of a sprite

export default function run(speed = 250, dir = -1) {
    return {
        id: "run",
        require: [ "pos", "area", ],
        add() {
                if (player.pos > this.pos) {
                    dir = -dir
                    this.play("runRight")
                } else if (player.posx < this.posx) {
                    dir = -dir
                    this.play("runLeft")
                }
        },
        update() {
            this.move(speed * dir, 0)
        },
    }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda