Closed sulysu closed 1 year ago
To implement the player to move along with a moving tile or rotating platform, the player is parented to the platform/ tile.
If the moving tile/ platform's transform scale is not (1, 1, 1), the player's transform scale will be changed relatively. For example, if the scale of a moving tile is 1.5, 1, 1.5 and the player's transform scale is the default (1, 1, 1). When the player is made the child of the tile, the local (relative) scale of the player becomes 0.66, 1, 0.66.
Unity will change the scale of a child object according to the parent object so that the multiplied total of both becomes 1, 1, 1.
After trying to set the player's scale from 1, 1, 1 forcefully to 1, 1, 1, I realized the fact that Unity wants to maintain a multiplicative scale result of 1, 1, 1. This is the nature of Unity Engine. I tried to attempt this by forcing it on both the collision function and the update function, both together and separately.
Finally, the fix which works is creating an empty child object to the moving tile and making that empty object the Player's parent. This works because the default scale of an empty game object is always 1, 1, 1. So, the multiplicative scale product rule of Unity is worked around.
Hierarchy when the Player Jumps on the Moving Tile becomes this -
When the player jumps out of the moving tile, the empty game object is destroyed and the player's parent is made Null (It has no parent after that)
Thanks, @sulysu pointing it out. This took some time and learning but figured it out.
Duplicate of #121
The Player won't move with the upper green tile.