When the player is on a vertically moving platform that is going down, there is a two pixel gap between the player and the platform. It's not there when moving up or horizontally.
The player and platform are both kinematic bodies and behave exactly the same if the platform is changed to a static body.
Everything I've tried has either done nothing or caused the player to stutter due to the platform moving away and then the player falling a short distance.
Attempting to manually alter the position of the player (set_pos()) after it does movement calculations still causes it to reset back to two pixels above the platform.
I printed the positions of the platform and player when moving up and moving down, so I know the distance between the origins of the two when moving down is almost exactly two pixels larger than when moving up.
I can fudge the sprite positioning during this situation to make the gap appear to vanish, but it still exists. I will do this until a solution is found (it isn't worth it for me to put any more hours than I already have into it). Can anyone figure out exactly why it's behaving this way, even if you don't have a solution?
Relevant player code:
velocity = Vector2(0, 0)
raycast = get_node("RayCast2D")
check_input() #left/right movement
surface = raycast.get_collider()
velocity.x += surface.velocity.x
if (surface.velocity.y > 0):
velocity.y += surface.velocity.y
velocity.y += GRAVITY
surface = null
var motion = velocity * delta
motion = move(motion)
var n = get_collision_normal()
motion = n.slide(motion)
velocity = n.slide(velocity)
Relevant Platform code:
velocity = Vector2(0, SPEED)
var cur_pos = get_pos()
if (cur_pos.y >= BOTTOM or cur_pos.y <= TOP):
velocity.y *= -1
var new_pos = cur_pos + velocity * delta
The setup with relevant parts highlighted:
Thanks for your help.