- Home /
Parent transform
Hey,
i've been searching but got no outcome of it..
I want to make a transform to an object, but the transformation script is on his child. so, if i use
myTransform = transform.parent;
on the child, it does a relative-to-parent transform, but i want it to move the parent (relative to global).
any thoughts?
*Edited lines where the transformation happens
//rotation myTransform.Rotate(0, (int)_turn * Time.deltaTime *rotationSpeed,0);
moveDirection = new Vector3(0,0,(int)_forward);
//back-forward moveDirection = myTransform.TransformDirection(moveDirection).normalized;
moveDirection *= swimSpeed;
I'm not sure what you're asking without more information. Changing the transform for a child occurs as it normally would. Changing the transform for a parent makes all children to the parent transform equally.
Answer by stingman · Jul 20, 2012 at 08:30 PM
A little more info would help like are you using a rigidbody on the parent? If so then just access the rigidbody of the parent and apply movement to that game object. I don't see any actual movement code above so i'll just give u a simple example You can do this in any script. For example...
var myTransform = transform.parent;
myTransform.Translate(Vector3.forward * Time.deltaTime, Space.World); // you would obviously replace this with your actual movement code
This will move the parent object relative to global like you wanted. Hope this helps
Answer by Meldow · Jul 20, 2012 at 09:30 PM
ohh, Space.World, didnt know that!
Will try that monday and report back! thx