Question by
tonibm1999 · Apr 25, 2016 at 12:46 PM ·
colliderrigidbody2dcollider2dparentchild
¿Why wont child move with parent?
So, I have a grenade without any physics while the player doesnt pickup it. It's a trigger with no rigidbody. When the player picks it up, a rigidbody2D is added, Trigger is set to false, and collisions with the player are set to be ignored. Also, rigidbody is set to kinematic (true). So, whats bad? The object will stay at air, not moving. Thanks in advance
void OnTriggerStay2D(Collider2D other)
{
if (Input.GetKeyDown(KeyCode.E) || (controls.E == true))
{
if ((other.tag == "player"))
{
GetComponent<BoxCollider2D>().isTrigger = false;
gameObject.AddComponent<Rigidbody2D>();
GetComponent<Rigidbody2D>().isKinematic = true;
Physics2D.IgnoreCollision(GetComponent<BoxCollider2D>(), other, true);
transform.position = other.transform.position;
transform.rotation = other.transform.rotation;
transform.parent = other.transform;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to set an object to be a child of another using c# 1 Answer
Enable Multiple Box Collides From Parent Object 2 Answers
2D Rigidboy, have child keep upright but allow parent to rotate 1 Answer
Why Object2D jump out collision? 1 Answer
Circle Collider 2d is slipping off box colider2d when it shouldnt 1 Answer