(Edit: This worked for my needs but I do hope someone with more experience in Defold and Lua can shed some light on how to properly approach this.)
I had the same problem some time ago. I made the Zenva platformer tutorial and afterwards, I wanted to see if I could translate some of what I’d learned by remaking the Godot Brackey’s tutorial in Defold (including using the enemy movement as a basis for the moving platforms). There were some references to what you’re proposing, parenting the player to the moving platform, on this forum from older posts, but no examples I could borrow from. I didn’t know how to use extensions, so I couldn’t rely on those. Plus, I really wanted to see what I could do with vanilla Defold.
So this is basically how I trial-and-errored my way to a solution: In on_message, just check if the message_id is a contact point response and if the message is from a group you’ve probably named “moving platform”. If it is, then set the moving platform as the parent of the player. Like this:
if message_id == CONTACT_POINT_RESPONSE then
if message.group == GROUND_LAYER then
handle_obstacle_contact(self, message.normal, message.distance)
elseif message.group == hash("moving_platform") then
go.set_parent(go.get_id(), message.other_id, true)
Now, if your player lands on a moving platform, it should move along with it like so:
It works okay at first glance, but the moment you get off the platform, the player still moves like its parented to the moving platform. So you have to add an else statement at the end to unparent the player from the platform when they are no longer colliding, like so:
else
go.set_parent(go.get_id(), nil, true)
end
So the entire snippet should look like this:
if message_id == CONTACT_POINT_RESPONSE then
if message.group == GROUND_LAYER then
handle_obstacle_contact(self, message.normal, message.distance)
elseif message.group == hash("moving_platform") then
go.set_parent(go.get_id(), message.other_id, true)
else
go.set_parent(go.get_id(), nil, true)
end
Then it should work fine.
I don’t know if this is the best way to do this, btw, I just know it worked for my modest use case.
Also, welcome to the community!