- Home /
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;
} }
Answer by Eks-Squared · May 31, 2015 at 05:51 AM
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.
Answer by john-essy · Oct 29, 2011 at 09:23 PM
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
Answer by ChrisSch · May 31, 2015 at 06:26 AM
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.
Answer by roadtofame · Dec 22, 2018 at 08:02 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024354im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to deal the 2d platform physics? 0 Answers
Triggering platform animation on colliding with Button 0 Answers
Character Controller falls through moving/rotating platforms (Not A Duplicate Post) 1 Answer
Ignore collision at high velocity. 1 Answer
What is the problem here ?( move script, c#, basic, platformer) 0 Answers