I have done some research on this and apparently my player is trying to match the scale of the parent since I'm using SetParent? And I have to manually adjust the scale but I don't know where to start.
My default player transform scale is (1, 1, 1) and it changes to roughly (0.2, 2.3, 0.2) when parented. Once I unparent, the scale does not go back to (1, 1, 1), but changes to the values (0.98, 0.99, 1.02). So no matter what, the scale messes up AND does not revert properly afterwards. I don't have a rigidbody and I am using a character controller.
public class PlatformSideToSide : MonoBehaviour
{
public GameObject Player;
public float moveAmount = 1.5f;
public float speed = 5.0f;
private Vector3 startPos;
void Start()
{
startPos = transform.position;
}
void Update()
{
// Making the platform move
Vector3 v = startPos;
v.x += moveAmount * Mathf.Sin(Time.time * speed);
transform.position = v;
}
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;
}
}
}