Search Unity

Explosion with ruin / scrap parts on a moving platform / level ground with collider

Discussion in 'Physics' started by Firlefanz73, Aug 25, 2022.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    I am working on a 2.5d arcade shooter with 3d gfx and physics but 2d camera way of old space shooters.

    In some level there is just empty space but some levels have "grounds" maybe a terrain or just a moving plane.

    Instead of moving the camera I move the ground (and it's belonging buildings wich are children of the ground or terrain) backwards (and the enemies etc too which are independent).

    Now of course if large explosions happen and if I let some parts / shards / ruin pieces fall to the ground, they do not scroll with that ground. How do I make them? Each ruin piece has a rigidbody.
    Can I make them a child of the ground and attach them somehow or something like that in a performant way?

    I tried them move with ground speed and direction but it is odd somehow...

    Any idea? Thanks a lot!
     
  2. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    Ah a sidescroller. Moving the ground IS the way to go with that.

    You can have it check for collision with the ground and then:

    Code (CSharp):
    1. targetGameObject.transform.parent = desiredParentGameObject.transform;
     
    Firlefanz73 likes this.
  3. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Yeah that's a simple solution, and it works at least for those that directly touch the ground / terrain, thanks!

    If I turn of rigidBody after a small while and set the tag of the "freezed" shard to "Terrain" too so it freezes others, it looks great :)
     
    knobblez likes this.