- Home /
Question is not specific enough. Don't ask others to write scripts for you.
Script that mimics a child object behavior.
I need this script, because for some complex reason, I must not attach this object as the child at all cost.
So what exactly is followed by the child object's transform and the parent object?
This child object will be far away from the target parent, and I need to replicate the behavior of how a child object works, any help?
C# preferred.
Thanks!
There are a lot of compiler error on that script, sorry for the late reply.
I get the main idea though. Thanks! (Would be great if you can fix them!)
And yes, I need it to absolutely be like a child object. The huge movement from the faraway child is intended.
Closing this thread as it's not asking a specific question, but rather asking users to write a script.
Answer by hav_ngs_ru · Nov 13, 2014 at 03:58 PM
Are you sure that you want to make it be absolutely like child? If a far "parent" object? A little rotation or "parent" may cause a huge movement of "child". But you can make it rotate synchronously around it's own pivot.
public GameObject ala_parent;
Vector3 d_rotation, d_position, d_scale;
void Start() {
d_rotation = Quaternion.FromToRotation(ala_parent.transform.up, transform.up);
d_position = transfom.position - ala_parent.transform.position;
p_scale = new Vector3(transfom.localScale.x/ala_parent.transfom.localScale.x, transfom.localScale.y/ala_parent.transfom.localScale.y, transfom.localScale.z/ala_parent.transfom.localScale.z);
}
void Update() {
transform.position = ala_parent.transform.position + d_position;
transform.rotation = d_rotation * ala_parent.transform.rotation;
transform.localScale = Vector3.Scale(ala_parent.transform.localScale, d_scale);
}