Player expands when parented to a moving platform gameobject.

So right now, I’m building a portal like game just for learning about Unity and programming.

I’m building a moving platform but my issue is that when I jump on the platform, my player expands due to it being parented to the platform.

Here is my code:

public class MovingPlatform : MonoBehaviour
{
    [SerializeField]
    float speed;

    [SerializeField]
    Transform startPoint, endPoint;

    [SerializeField]
    float changeDirectionDelay;


    private Transform destinationTarget, departTarget;

    private float startTime;

    private float journeyLength;

    bool isWaiting;

    [SerializeField] GameObject player;



    void Start()
    {
        departTarget = startPoint;
        destinationTarget = endPoint;

        startTime = Time.time;
        journeyLength = Vector3.Distance(departTarget.position, destinationTarget.position);
    }


    void FixedUpdate()
    {
        MovePlatform();
    }

    private void MovePlatform()
    {


        if (!isWaiting)
        {
            if (Vector3.Distance(transform.position, destinationTarget.position) > 0.01f)
            {
                float distCovered = (Time.time - startTime) * speed;

                float fractionOfJourney = distCovered / journeyLength;

                transform.position = Vector3.Lerp(departTarget.position, destinationTarget.position, fractionOfJourney);
            }
            else
            {
                isWaiting = true;
                StartCoroutine(changeDelay());
            }
        }


    }

    void ChangeDestination()
    {

        if (departTarget == endPoint && destinationTarget == startPoint)
        {
            departTarget = startPoint;
            destinationTarget = endPoint;
        }
        else
        {
            departTarget = endPoint;
            destinationTarget = startPoint;
        }

    }
    IEnumerator changeDelay()
    {
        yield return new WaitForSeconds(changeDirectionDelay);
        ChangeDestination();
        startTime = Time.time;
        journeyLength = Vector3.Distance(departTarget.position, destinationTarget.position);
        isWaiting = false;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.transform.parent = transform;
        }
    }

    private void OnCollisionExit(Collision other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            other.transform.parent = null;
        }
    }
}

Any help I will truly be thankful for, thanks.

Hello there!

Changing a gameObject parent do not change its scale, any scale.

Objects have 2 scale (and 2 positions and 2 rotations):

Scale (which is absolute, relative to World) and localScale (which is relative to its parent). The same for position and rotation.

So, when you change the parent, what is changing is the local Sclae to adapt to the new parent, to make the “absolute” sclae continues beeing the same.

If the character is changing its scale is because you are changing some scale on its parent or on itself, but not for the fact of changing the parent.

Check for your code.

(Tip: Changing the parent via code, is the same as changing it from the hicheracy, it gives the same result, so, try to do it in the hicheracy while playing to see the result of changing the parent)

Bye!