- Home /
child collider2D problems after parenting to moving platform.
Hi
I'm having trouble with my characters collision after I parent it to a moving platform. The real problem is that sometimes the collision works as intended and other times it doesn't collide at all.
This is the code for handling collision with "Deadly" objects.
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Deadly" && !dead)
{
// character dies
}
}
and the platform is setup like this.
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
other.transform.parent = gameObject.transform;
move = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if(other.tag == "Player")
{
other.transform.parent = null;
move = false;
}
}
So as I said, while the player is childed to the platform the collision with "Deadly" objects sometimes works great and other times gets ignored completley.
Both the player and the moving platform have rigidbodies2D (Player is non-kinematic and platform is kinematic). The platform is made up of 1 empty gameObject with the sprite(colliders and script attached) and 6 checkpoints as children. What I do is move the checkpoints to where I want the platform to move then use Vector3.MoveTowards to move to the next checkpoint.
I Have both screenshots and video of the problem but cant seem to get upload to work.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143924im_/https://answers.unity.com/themes/thub/images/avi.jpg)