Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Different collision results in some areas.

Discussion in 'Physics' started by Pedro2103, Jul 26, 2020.

  1. Pedro2103

    Pedro2103

    Joined:
    Jul 13, 2020
    Posts:
    1
    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:


    Player hierarchy, the "player_a", "player_b" and "player_c" are player's parts that will break up, I just unparent them:


    Player rigidbody and collider:



    When the asteroid collides with the player, this is called:
    Code (CSharp):
    1.  
    2.             this.transform.DetachChildren();//Unparent children
    3.             Rigidbody2D rb_Asteroid = collision.gameObject.GetComponent<Rigidbody2D>();
    4.             Vector2 Asteroid_Velocity = rb_Asteroid.velocity;
    5.             float AV_Asteroid = rb_Asteroid.angularVelocity;
    6.  
    7.             Destroy(this.gameObject);//Destroy player gameobject
    8.  
    9.             //Get detached children
    10.             GameObject _A = GameObject.Find("player_a");
    11.             GameObject _B = GameObject.Find("player_b");
    12.             GameObject _C = GameObject.Find("player_c");
    13.            
    14.             Rigidbody2D rb_A = _A.GetComponent<Rigidbody2D>();
    15.             Rigidbody2D rb_B = _B.GetComponent<Rigidbody2D>();
    16.             Rigidbody2D rb_C = _C.GetComponent<Rigidbody2D>();
    17.  
    18.             //Enable 'Simulate' rigidbody
    19.             rb_A.simulated = rb_B.simulated = rb_C.simulated = true;
    20.  
    21.             //Change velocity
    22.             rb_A.velocity = rb_B.velocity = rb_C.velocity = Asteroid_Velocity;
    23.             rb_A.angularVelocity = rb_B.angularVelocity = rb_C.angularVelocity = AV_Asteroid;
    24.