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

140
Views
My player slides off moving platform. Javascript canvas game

I'm trying to get my player to stay on the moving platform. Possibly need to add something in here? Gravity? I'm still pretty new at this.

export function collisionTop({ object1, object2 }) {
  return (
    object1.position.y + object1.height <= object2.position.y &&
    object1.position.y + object1.height + object1.velocity.y >=
      object2.position.y &&
    object1.position.x + object1.width >= object2.position.x &&
    object1.position.x <= object2.position.x + object2.width
  )
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I read correctly, the problem you have is that the player does not move when the platform it is standing on moves. To fix this problem, whenever you move the platform, you should check if the player is standing on the platform (with a collision function), then if the player is standing on the platform, move the play the same distance in the same direction as the platform you are moving. It might look something like this (I don't know your code, so this is a rough guess):

function movePlatform(dx, dy) {
    if (collisionTop(player, platform)) {
        player.position.x += dx;
        player.position.y += dy;
        platform.position.x += dx;
        platform.position.y += dy;
    }
}
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!