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

106
Views
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
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!