- Home /
Keep Parent scaling independent to Child's (C#)
With this script it makes the child objects rotate based on the parents position, I want to implement something that will allow me to change the parents scale but not have that affect the child scale. Any ideas how I could implement that into this script ?
using UnityEngine; using System.Collections;
public class Tutorial_3_Q1 : MonoBehaviour
{
public Transform _parent;
private float eulerAngles;
void start()
{
}
void Update()
{
transform.RotateAround(_parent.position, _parent.rotation.eulerAngles, 50 * Time.deltaTime);
print(transform.eulerAngles.x);
print(transform.eulerAngles.y);
print(transform.eulerAngles.z);
}
void OnGUI() {
GUI.Label(new Rect (10, 10, 200, 20),"Euler Angle x ="+ transform.eulerAngles.x);
GUI.Label(new Rect(10, 30, 200, 40), "Euler Angle y ="+ transform.eulerAngles.y);
GUI.Label(new Rect(10, 50, 200, 60), "Euler Angle z ="+ transform.eulerAngles.z);
}
}
Answer by Glurth · Feb 02, 2015 at 11:45 AM
If you must keep them as child objects: you will need to apply the inverse of your parent scaling. for example, if you are increasing the parent scale(evenly to each axis) 1.5 like this:
parent.transform.localScale *= 1.5f;
//to keep this child the same size you would need to do the following;
child.transform.localScale *= 1.0f / 1.5f;
// 1.5f could (and should) obviously be a variable instead of a number
But be careful, this may have unexpected effects when combined with other transforms.
Your answer
Follow this Question
Related Questions
Collider Doesn't Rotate in Sync With Mesh 1 Answer
Avoid scaling GameObject after parenting 2 Answers
Best Way to turn part of a 3D model in game 1 Answer
Child model skinned mesh does not scale with parent 2 Answers
UI scaling based on content 1 Answer