# Moving platform as a parent

**URL:** <https://forum.defold.com/t/moving-platform-as-a-parent/14796>\
**Category:** Questions\
**Created:** [December 17, 2017, 5:46pm UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796 "2017-12-17T17:46:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdou23](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Abdou23](https://forum.defold.com/u/Abdou23)\
**Post date:** [December 17, 2017, 5:46pm UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/1 "2017-12-17T17:46:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [December 17, 2017, 5:48pm UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/2 "2017-12-17T17:48:54Z")

</div>

> [@How to find a game objects collision group?](https://forum.defold.com/t/how-to-find-a-game-objects-collision-group/14785/2):
>
> Hi @bill.northcott! In the documentation for [collision\_response](https://www.defold.com/ref/physics/#collision_response:other_id-other_position-other_group-own_group) you’ll find message.other\_group which should do what you want.

---

<div class="post-metadata">

**Author:** ![Abdou23](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Abdou23](https://forum.defold.com/u/Abdou23)\
**Post date:** [December 17, 2017, 6:28pm UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/3 "2017-12-17T18:28:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [December 18, 2017, 9:41am UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/4 "2017-12-18T09:41:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Abdou23](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Abdou23](https://forum.defold.com/u/Abdou23)\
**Post date:** [December 18, 2017, 11:53am UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/5 "2017-12-18T11:53:27Z")

</div>

Both the character and the platform are kinematic.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [December 18, 2017, 11:57am UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/6 "2017-12-18T11:57:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Abdou23](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Abdou23](https://forum.defold.com/u/Abdou23)\
**Post date:** [December 19, 2017, 9:50pm UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/7 "2017-12-19T21:50:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [December 20, 2017, 7:32am UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/8 "2017-12-20T07:32:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [December 20, 2017, 7:48am UTC](https://forum.defold.com/t/moving-platform-as-a-parent/14796/9 "2017-12-20T07:48:58Z")

</div>

> [@britzl](#):
>
> 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.
