- Home /
Child position not updating immediately?
I want to attach a GameObject to my player as soon as they touch, because I want this object to "follow" my player (as if they are holding it). This is the code I attached to my player:
void OnCollisionEnter2D(Collision2D collision) {
collision.collider.enabled = false;
collision.rigidbody.isKinematic = true;
collision.transform.parent = this.transform;
collision.transform.localRotation = new Quaternion();
collision.transform.localPosition = new Vector3(0.5f,0,0);
}
When my player runs into the object it gets stuck in its current position and is jittering for ~1/2 second. Then it starts followig the player from there. Since the player moved in that time it is not in its desiered positon, but somewhere far behind the player.
Thanks.
Try using gameObject.transform ins$$anonymous$$d of "this.transform".
Your answer
![](https://koobas.hobune.stream/wayback/20220613151300im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Set Children into a circle. 1 Answer
Camera rotation around player while following. 6 Answers
Simulate Child Parent Relationship (parent constraint) 2 Answers
How to get child object on top of his parent. 1 Answer
How make an object child of other object without changing the child position? 0 Answers