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
)
}
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;
}
}