- Home /
Player not sticking to moving platform
Hello!
I have an issue with my moving platforms. I'm trying to get the player to follow the platform and not slide around.
So I've tried this bit of code:
void OnCollisionEnter2D(Collision2D other)
{
if (other.transform.tag == "movingPlatform")
{
player.isKinematic = true;
transform.parent = other.transform;
}
}
But as you can see in the below images, the parenting process mucks up the size of the player. I'm not sure why because if I manually parent the player it works fine.
Any ideas as to how to fix this?
Answer by tormentoarmagedoom · Sep 13, 2017 at 09:06 AM
Hello @Sabrekitty
This happens because the first parent and the new parent (platform) does not have the same Transform.localScale .
You have then 2 options:
1- Run the game in the editor, and once the character changes size, resize it manually, and copy the new transform values. Then at the script, after changing the parent, change it transforms with the saved values
2- Make all scales of all platforms (1, 1, 1) to prevent deforming when changing parents.
Your answer
Follow this Question
Related Questions
tranform parent makes character blow up in size 2 Answers
2.5D platformer main character collision 1 Answer
Making a Child/Parent Based Moving Platform? 2 Answers
Platform pathfinding 0 Answers
2D 360 degress platformer example needed 0 Answers