Moving Platforms & Scale (Parent/Child)

Hi guys, I’m hoping you can help because this is driving me up the wall.

I’m still new to coding and Unity work in general, so if you could explain in detail what you mean, that would be great. I have gone through every single google page and Unity Answers page looking for answers.

My problem is this. I am creating a 2D platform game for a school assessment. In it, the player (currently a sphere, but will be replaced with an imported asset) moves onto a moving platform (simple collider) which will move either up and down, or left and right a set amount of space. The player needs to retain the ability to jump at will whilst on the platform. The way most people seem to get these to work is by having the player parented to the moving platform OnTriggerEnter or OnTriggerStay (this is currently in my player script) and OnTriggerExit, the parent/child relationship is broken.

This is all in C# btw.

void OnTriggerEnter(Collider otherObject)
 { 
 if(otherObject.gameObject.tag == "MovingPlatform")
 {
            transform.parent = otherObject.transform; 
 }
 }

 void OnTriggerExit(Collider otherObject) 
 { 
 if(otherObject.gameObject.tag == "MovingPlatform"){
         transform.parent = null; 
         }

This works well, and as it’s a group assessment, I don’t want to change the way these work in any significant way because it has been done by a partner. The problem is that when the player enters the MovingPlatform Collider, it inherits the parents scale properties. Because the platforms are scaled differently, this makes the player squish hideously. Searching far and wide, I found ways to change the scale of objects and included that into the OnEnter and OnExit functions, but it doesn’t seem to work for OnEnter.

I have done it this way:

 transform.localScale = new Vector3(1F, 1F, 1F);

As well as this way:

Vector3 scale = transform.localScale;
scale.y = 1F; 
scale.x = 1F; 
scale.z = 1F; 
transform.localScale = scale;

I have read that the scale has to be relative to the platform, which is scaled 140,100,100. I have tried changing the scale values to accommodative for this, but it doesn’t seem to work. I have read you may have to apply the scale to the player object (as you can see it’s 1,1,1) inversely, but I am not sure how to do this.

Any help would really be beneficial. Please be aware that I have searched through the forums and answers for this, but nothing has helped so far. I have also tried to create an empty game object with scale 1,1,1 and use that as the parent of the platform, but the player still inherits the scale of the platform gameobject itself.

You could layer your hierarchy a little more to separate the position and scale of the platform.

For example:
PlaneTransform(GameObject with Transform)->PlaneScale(GameObject with Transform and MeshFilter)

PlaneScale is a child of PlaneTransform.

Here you would modify PlaneScale to get the scaling of the mesh that you need, and PlaneTransforms position to move it around. When you parent the Player to PlaneTransform it will inherit only the position, and not the scale.