- Home /
change y position of child when relative to parent and iTween
i have parent/child object in my scene. for moving child i use iTween.MoveTo
. but when i change the parent position the child position doesn't change and it play animation in it's start point that animation is played. also when i set transform.position
to parent.transform.position
or localPosition
to Vector3.zero
nothing happen and child y position is still in it's first instansate position.
this is my Restart method that call when position of parent is changed :
public void Restart() { if (RandomDirection) { int rnd = Random.Range(0, 2); if (rnd == 0) { direction = Direction.Left; } else if (rnd == 1) { direction = Direction.Right; } } if (RandomSize) { float width = Random.Range(0.5f, 1.5f); Vector3 localScale = transform.localScale; localScale.x = width; transform.localScale = localScale; } if (RandomSpeed) { Speed = Random.Range(5f, 10f); } else { Speed = 1f; }
float move = 0f;
Vector3 pos = transform.position;
if (UseParentYPosition)
{
Transform parent = GetComponentInParent<Transform>();
pos = parent.position;
}
else{
pos = transform.position;
}
if (direction == Direction.Left)
{
pos.x = leftStartPosition;
move = rightStartPosition;
}
else if (direction == Direction.Right)
{
pos.x = rightStartPosition;
move = leftStartPosition;
}
transform.position = pos;
iTween.MoveTo(this.gameObject, iTween.Hash("x", move, "easetype", iTween.EaseType.linear, "looptype", iTween.LoopType.loop, "speed", Speed));
}
so my question is how to change y postion of child to parent y position when the position of parent is changed.
Your answer
Follow this Question
Related Questions
Child object getting transformed out side the scene on collision? 1 Answer
Getting screenshots within a loop? 2 Answers
Problem transferring children to a new parent 2 Answers
Model rotation and hierarchy of game objects - not rotating! 1 Answer
Setting a Transform or GameObject SyncVar from a Command 0 Answers