I found the way to make my character move with a platform is to set the platform as a parent. I’m trying to do that in the “on_message” function and after testing for collision with the platform group I have this line of code:
go.set_parent({parent_id = ?? })
How can I get the id of the object I just collided with?
Thanks.
It works but is giving me weird behavior, the character doesn’t get the same position as the platform and it keeps randomly rotating. I tried setting “keep_world_transform” to “0-1” but didn’t work.
It seems that some manual calculations need to be made in order to get the positioning right.
Oh, you can’t child a dynamic object to a kinematic, if that is what you are doing. The physics engine will try to simulate the childed object and Defold’s transform of parent child hierarchies will collide with that.
Both the character and the platform are kinematic.
Ok, good. The thing with “keep_world_transform” is that it takes into consideration the world transform when set. If you want to set the child to the same position as the parent, it should be set to (0, 0, 0) and then childed without keeping the world transform. All child-positions are relative to the parent’s position, rotation and scale as soon as it’s childed.
It works now as it should. Now I need when the character leaves the platform (stops contacting it) to detach it from It as a parent. But, I can’t find a function for collision exit detection.
In my “on_message” function I use multiple "if-elseif " statements in “contact_point_response” to check collisions with different objects
What if you keep track of a ground_contact variable and one ground_contact_previous_frame and if the latter was true and the former false then you’ve left the platform.
Yes, that’s how I use to do it. Reset the variable at the end of each update(), then set it on contact.