How to lift stacked boxes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JeroMN

I have two characterBody2d boxes and an animatableBody2d movable one-way platform. When the two boxes are stacked together, the platform can only lift one box. How can I lift the two boxes together?

box code

extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta):
velocity.y += gravity * delta * 10
:bust_in_silhouette: Reply From: RohanLockley

i’m not the best person to answer but perhhaps i can help out .

it seems to me you are trying to move the platform up, though im not sure why you would use gravity in this equation. you could turn the gravity or weight of the boxes down, the speed you move up, or what i used to do in unity when it came to working with platforms that moved, make the object on the platform a child thereof so long as they are in contact, allowing you to go up, down, left or right without them falling off, save for intentional game design.

i don’t have functional code for you to do that however, i’m still figuring gd script out at the moment. still, i hope this is of some help?