How to move child with parent within the same frame. (Before trigger events)

I have 2 game objects - the player, a moving platform. The platform has 2 box colliders; one a trigger, the other not. The player has a capsule collider and a character controller. When the player lands on top of the platform, it enters the trigger and makes the platform its parent so that the platform can move the player with it. This works perfectly until the platform moves downward on the Y axis. What I believe is occurring is the following:

  1. Platform moves down
  2. Trigger Exit activated
  3. Platform removed as player parent
  4. Gravity applies to player
  5. Player enters trigger
  6. Repeat

This causes the player object to constantly bounce the entire way down. Is there a way to make the child (player) move with its parent (platform) within the same frame, or before trigger events occur?

My code for reference:

/////////////////////////////
//within player object
/////////////////////////////
void OnTriggerStay(Collider other)
    {
        if(other.gameObject.tag == "Platform")
        {
            transform.parent = other.gameObject.transform;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if(other.gameObject.tag == "Platform")
        {
            transform.parent = null;
        }
    }

////////////////////////
// Within platform
////////////////////////
void Update () {

        if (!isResting)
        {
            if (xAxis)
            {
                transform.position += new Vector3((speed * (xInvert ? -1 : 1)) * Time.deltaTime, 0, 0);
            }
            if (yAxis)
            {
                transform.position += new Vector3(0, (speed * (yInvert ? -1 : 1)) * Time.deltaTime, 0);
            }
            if (zAxis)
            {
                transform.position += new Vector3(0, 0, (speed * (zInvert ? -1 : 1)) * Time.deltaTime);
            }
        }

        elapsedTime += Time.deltaTime;

        if(elapsedTime >= travelTime && !isResting)
        {
            elapsedTime = 0f;

            xInvert = !xInvert;
            yInvert = !yInvert;
            zInvert = !zInvert;

            if(restTime > 0f)
            {
                isResting = true;
            }
        }

        if(isResting)
        {
            if(elapsedTime >= restTime)
            {
                elapsedTime = 0f;
                isResting = false;
            }
        }

    }

According to the execution order (image below), OnTrigger events get called before Update events. If this is true, how is it possible then for a parent to move during update and not have the child move with it (assuming the child has no movement) at the same time, before an OnTriggerExit() can occur?

Things I’ve tried:

  • Make player stationary (won’t move until its platform’s child)
  • putting player on LateUpdate so as to move after the updated platform
  • Increasing trigger size (which slightly works, but causes very awkward movement)

The issues is the player object leaves the trigger zone [only] when the platform moves down, causing a bouncing effect the whole way down. The only reason this can happen is if the platform moves without the player, causing a TriggerExit. How can this be avoided?

Good day @uulamock_unity !!

I did not read your code, i have no time :smiley: I recommend you to read this manual showing order of executions , to decide when/where to execute your commands to prevent this kind of problems

If helped, Accept the answer as correct!!

Bye :smiley: :smiley: