0

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;
        }
    }
}
dangoqut132
  • 17
  • 10
  • caching it before collider and loading it back after unparent isn't an option? – Nefisto Mar 07 '23 at 12:49
  • Why don't you set your global scale to Vector3(1,1,1) before and after parenting your player gameobject – thunderkill Mar 07 '23 at 14:10
  • It shouldn't matter. This happens due to floating point inaccuracies - [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) - happening when Unity converts between the two lossy scales and applies a new local Scale – derHugo Mar 08 '23 at 15:21
  • @derHugo but you can see the scale change in run time. My character shrinks and basically flattens horizontally which isn't good right? – dangoqut132 Mar 09 '23 at 12:26

0 Answers0