- Home /
Child Obj Ignoring Parents Rotation! Help
Hello! So i have a simple JAVAscript <(Only Please), turning my parent obj (diamond) and i want the 3D plane infront (Name of it) to NOT rotate. I want something like:
transform.rotation = Quaternion.identity;
Although this DOES Ignore Rotation it ALSO ignores position change which i DONT want. Plus it sets the rotation to 0,0,0 and i want it to automatically at start FIND the rotation of the obj the script is attached to (child that is) and store that, THEN set that as the rotation identity of that CHILD OBJ.
I want the CHILD obj to be able to Translate anywhere with the Parent, just NOT rotate!
Thanks so much for the Help, Daniel
Answer by clunk47 · Jul 11, 2013 at 04:04 AM
Get the startup rotation, then keep it at that in update.
var defaultRot : Quaternion;
function Start()
{
defaultRot = transform.rotation;
}
function Update()
{
if(transform.parent != null)
transform.position = transform.parent.transform.position;
transform.rotation = defaultRot;
}
Thank you! @clunk47 I want to ALLOW Position change as well though! I want this child obj to be able to translate with the parent in any direction, just not rotate. You got an Idea?
Thanks, $$anonymous$$
Position should be automatically synced w/ the parent object. $$anonymous$$ake sure the object isn't losing its parent at runtime by checking if the parent is null (not available). Edited answer to show this.
$$anonymous$$y bad, I'll be more specific. Define your variable @ the top of your script.
var defaultRot : Quaternion;
function Start()
{
defaultRot = transform.rotation;
}
function Update()
{
transform.rotation = defaultRot;
}
Edited Answer.
transform.position is a Vector3. transform.rotation is a Quaternion.
Haha! Thank you! :P Yes it DOES! Figured it all out!! You have educated me so well with this quaternion identity stuff thank you :P I found out it was all in my iTween animation, i changed the move to to $$anonymous$$ove Add!! This added to what ever the parent was and Thus kept the obj with it and happy :D
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Gun Rotation 2 Answers
How to make a animation rotation js.script? 2 Answers
Finding A Rigidbody's Rotation Speed And Direction 2 Answers
Lerp with raycast hit.normal? 2 Answers