- Home /
Different collision results in some areas.
Hello, I'm trying to clone the Classic Asteroids but I'm getting problem with physics. When the player hits the asteroid, he just break up, pictures bellow:
Before crash:
After a normal crash:
After a problematic crash, the spacecraft just separate and it's still being 'dragged' by the asteroid:
Video: https://www.youtube.com/watch?v=8YVeRRTrZZA&feature=youtu.be
Player hierarchy, the "player_a", "player_b" and "player_c" are player's parts that will break up. I just unparent them when the asteroid collides:
Player rigidbody and collider:
When the asteroid collides with the player, this is called:
this.transform.DetachChildren();//Unparent children
Rigidbody2D rb_Asteroid = collision.gameObject.GetComponent<Rigidbody2D>();
Vector2 Asteroid_Velocity = rb_Asteroid.velocity;
float AV_Asteroid = rb_Asteroid.angularVelocity;
Destroy(this.gameObject);//Destroy player gameobject
//Get detached children
GameObject _A = GameObject.Find("player_a");
GameObject _B = GameObject.Find("player_b");
GameObject _C = GameObject.Find("player_c");
Rigidbody2D rb_A = _A.GetComponent<Rigidbody2D>();
Rigidbody2D rb_B = _B.GetComponent<Rigidbody2D>();
Rigidbody2D rb_C = _C.GetComponent<Rigidbody2D>();
//Enable 'Simulate' rigidbody
rb_A.simulated = rb_B.simulated = rb_C.simulated = true;
//Change velocity
rb_A.velocity = rb_B.velocity = rb_C.velocity = Asteroid_Velocity;
rb_A.angularVelocity = rb_B.angularVelocity = rb_C.angularVelocity = AV_Asteroid;
[3]: https://youtu.be/8YVeRRTrZZA
Well you set rb_A.velocity = rb_B.velocity = rb_C.velocity = Asteroid_Velocity;
so i wouldnt be suprised if the asteroid was just dragging along the player.
Answer by Pedro2103 · Jul 29, 2020 at 10:30 PM
I solved it by adding a box collider on the middle of the player. I think this is a workaround but it's working fine: