- Home /
Question by
Nishkarsh_Jain · Nov 11, 2020 at 03:05 PM ·
parentmoving platformparent transformparent and child
How do I move it along with the platform while still keeping it's original scale!!
I want my player(cube) to move along with a moving platform (rectangle)! I tried setting the moving platform as a parent to the player, but then it's dimensions also get changed and it becomes a rectangle! How do I move it along with the platform while still keeping it's original scale!! Here's my code :-
public GameObject Player;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == Player)
{
Player.transform.parent = transform;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject == Player)
{
Player.transform.parent = null;
}
}
Comment
Not certain this would work, but try adding a bool, something like "isOn". In the OnTriggerStay make it true, and OnTriggerExit, make it false. Then in the update, do the Player.transform.parent = transform if isOn, and the opposite. I have that on an elevator script and it works.