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:
func _ready():
velocity = Vector2(0, 0)
raycast = get_node("RayCast2D")
raycast.add_exception(self)
func on_ground():
return raycast.is_colliding()
func _fixed_process(delta):
check_input() #left/right movement
if (on_ground()):
surface = raycast.get_collider()
velocity.x += surface.velocity.x
if (surface.velocity.y > 0):
velocity.y += surface.velocity.y
else:
velocity.y += GRAVITY
surface = null
var motion = velocity * delta
motion = move(motion)
if (is_colliding()):
var n = get_collision_normal()
motion = n.slide(motion)
velocity = n.slide(velocity)
move(motion)
Relevant Platform code:
func _ready():
velocity = Vector2(0, SPEED)
set_fixed_process(true)
func _fixed_process(delta):
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
set_pos(new_pos)
The setup with relevant parts highlighted:

Thanks for your help.