Prevent changes in scale when parenting rotated child
Ok so am building a game where objects need to be re parented from one platform to another. The platform's and the player's scales are both set to 1,1,1 and those scales are never changed in code. However, as soon as the child is parented to the platform, the child x and z scales are set to 0.2 without visually changing the scale. At this point, rotating the child causes it to scale and skew wildly.
It seems like unity is trying to update the local scale without compensating for the local rotation...How do I prevent this? Why does the scale of my player change? Or is this a bug?
Answer by Cuttlas-U · Sep 10, 2017 at 04:14 PM
Do it like this :
transform.SetParent(ParentTransform, false);
the "False" means it wont be affected by the parent;
Answer by CiberX15 · Sep 10, 2017 at 04:22 PM
Actually. In my case I simply screwed up and was parenting to the wrong object. I had some old logic that I forgot was there that was parenting to the visual platform (a re scaled cube) instead of the logic of the platform which was an empty with no scaling.
Answer by Rispat-Momit · Sep 07, 2018 at 08:17 PM
Hi there! I figure out this solution :D
At the FixeScale set up the size of your child you need and at the parent set your parent model.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class FixedScale : MonoBehaviour {
public float FixeScale =1 ;
public GameObject parent;
// Update is called once per frame
void Update () {
transform.localScale = new Vector3 (FixeScale/parent.transform.localScale.x,FixeScale/parent.transform.localScale.y,FixeScale/parent.transform.localScale.z);
}
}
i don't think this is right at all. might be better with OnTrigger or OnCollide maybe..? :)