- Home /
Question by
ska101 · Jan 08, 2017 at 08:47 AM ·
c#collisionparent-childparent transform
Snaping/Merging game objects together
I have two types of game objects "redBall" and "blackBall".
They are moving in z direction at random speeds.
What would be a good way of writing a script so that if they collide they would move forwards as one (with black balls speed). I want it to almost look like they are one object instead of two.
On my blackBall I have a script that has this. (Also, blackBall is a child of an empty object)
void OnCollisionEnter(Collision col) {
if (col.gameObject.name == "RedBall") {
Debug.Log ("Collision");
col.gameObject.transform.parent = transform;
}
}
With that last line i am trying to merge both objects so they have same parent hoping they would behave as one object.
I think i could accomplish what i want if I modify the speed of one object to match the speed of the other object if collision occurs but i feel like there might be a better solution to this.
Comment