Object deforms when parenting to a moving platform.

I am trying to implement moving platforms in a side-scrolling game. I have a ball that can rotate and move freely - whenever it lands on a moving platform it deforms - the ball stretches in all sorts of ways - does anyone know how to counter this or make moving platforms work? I’m currently using the parenting method but it’s not working right for some reason. This is the code I have on the moving platform:

function OnCollisionEnter(collision : Collision)
{
if(collision.rigidbody.tag == “Player”)
{
collision.transform.parent = transform;
}
}

I had this same issue in the past. The problem is that the ball is taking on the scale of what ever your platform is. That means if your platform has an odd scale, the ball will be scaled the same way.

A very easy solution would be to create your own platform in an external modelling application like Maya or Blender. Keep in mind that you will have to APPLY the scale to whatever platform you create (you should scale the platform to what ever scale your player is).

When you touch the platform you created, more odd deformations will happen. Let me know if this solution works.

Create an Empty GameObject then parent the object to what it is you want to parent to then make the object that defects a child of the empty gameObject.

Hope this solves your problem

Eks Squared is correct, but if you don’t want to do that, simply create an empty object with scale of 1,1,1, a collider, and make the platform a child of it, without a collider. Then when the ball lands on it, just parent it to the empty game object.

Alternatively you can leave the empty game object without a collider, and put it on the platform itself, but I’m unsure if that would work the same, as there’s been a few physics changes over the years.

Just had this problem and accidentally solved it. Here’s the code I’m using:

    public GameObject TheLedge;
    public GameObject ThePlayer;

    void OnTriggerEnter()
    {
        ThePlayer.transform.parent = TheLedge.transform;
    }

    void OnTriggerExit()
    {
        ThePlayer.transform.parent = null;
    }

Make your player the child of an empty and set that empty as ThePlayer gameobject and your platform as ThePlatform gameobject. I assume you already have this solved but hopefully this helps someone because this took me some time to get right.