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

173
Views
How do I make a sprite point to another sprite in javascript?

I am trying to make a game where a sprite has to follow food and eat it, so far I got the following code to work but I want the sprite to actually point to the closest food and follow it

I dont know how to make it follow the closest food, only all of it but it works sort of anyways

How do I make it point to the food? If possible also how would I make it move only to the closest piece of food?

// custom component controlling organism movement
export default function MoveToFood() {
    return {
        id: "MoveToFood",
        require: ["pos", "area",],
        add() {
            //Organism move towards food
            onUpdate("Food", (f) => {
                dir = f.pos.sub(this.pos).unit();
                this.move(dir.scale(Speed));
            })
        },
    }
}
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!