Unity - Parent with children fall apart

1.1k views Asked by At

I have a player character, made of some cubes, spheres and a capsule. I created the empty object Player and all body parts of the player are a child of Player. I have two planes, with a moving platform in between. I can walk and jump on the normal planes and the walls, but when the player is on the moving platform the bodyparts of the player fall apart. Maybe it's something really stupid, but I just started with Unity.

This is what goes wrong, the player falls apart on the moving platform: http://nl.tinypic.com/r/207s3sz/9

And below the information about the overview, the player, the body parts, and the moving platform with according character-holder. All bodyparts have the same properties as the body part on the screenshot. Can anyone help me with what goes wrong here? How can I transport the whole player by the moving platform?

enter image description here

enter image description here

HoldCharacter script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HoldCharacter : MonoBehaviour {

    void OnTriggerEnter(Collider other) {
        other.transform.parent = gameObject.transform;                        
    }

    void OnTriggerExit(Collider other)
    {
        other.transform.parent = null;
    }
}
2

There are 2 answers

0
David Espino On BEST ANSWER

You just need to disable the isTrigger flag. Here are some insights

so how Is Trigger works is that... it will fire OnTriggerExit and OnTriggerEnter, but it will let the object go through it. If you disable the IsTrigger, then you need to move the logic to OnCollisionEnter on OnCollisionExit methods. If the isTrigger uncheck kind of worked, maybe is just the fact that you move the logic for HoldCharacter to OnCollisionEnter and OnCollisionEnd respectively Like this:

void OnCollisionEnter(Collision collisionInfo) { 
   collisionInfo.gameObject.transform.parent = gameObject.transform; 
} 
void OnCollisionExit(Collision collisionInfo) {
    collisionInfo.gameObject.transform.parent = null; 
}

Regards

1
CrafterOfWorlds On

If I'm correct, the children of objects with Rigidbodys have physics as well. Maybe put the rigidbody on a child of the player, like so.

Player -head -arms -legs -empty gameobject with rigidbody