Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Options for implementing mining/digging in an asteroid belt game?

Discussion in '2D' started by MossTheTree, Feb 3, 2023.

  1. MossTheTree

    MossTheTree

    Joined:
    Jan 12, 2023
    Posts:
    4
    I'm early in my game dev journey and trying to learn by doing, but could use some advice to get me in the right direction.

    I'm prototyping a basic asteroid mining game, which includes:
    • Multiple asteroids, each moving (along predefined paths) and rotating, with their own gravity (only acting upon the player). This part is done.
    • Player that can travel between and land on asteroids. Also done.
    What I'm trying to figure out now is what system to build to enable the player to dig into the asteroid. The few possible options I've thought about or found online include:
    • Building each asteroid with a tilemap, then removing a tile on each dig action. I think I can figure this out easily enough, but the problem is that I guess I'd need a tilemap for *each* asteroid as they are moving and rotating independently from each other. I'm assuming that would become quickly resource intensive and unwieldy.
    • Using pixel perfect destructible terrain (like the old Worms games). I've found several examples that are frankly beyond my current understanding, but regardless they're more granular than I'd like - I'd prefer to have it feel more like tiles or blocks (like Terraria for example)
    • Using sprite masks to remove parts of the asteroid when digging, and then somehow modifying/redrawing the collider to enable the player to descend into the hole. In my mind this makes sense, but I haven't found any examples of how to dynamically recalculate the collider based on the new shape after masking. My reading also tells me that recalculating colliders is resource intensive.
    • Doing a scene transition upon landing, then managing the digging in a separate scene using a tilemap. The benefits of this are obvious, but the main drawback I see is what I guess is the difficulty of showing the results (holes, tunnels etc.) on the asteroid after having transitioned back to the main scene.
    Can anyone give me some pros and cons of these or other solutions or point me in the right direction? I'm not looking for specific code, just an approach that I can try to work toward. Thanks!
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,470
    Maybe one of these videos will give you a clue? upload_2023-2-3_13-53-3.png

    Also, don't worry too much about resource intensity this early in your journey. Unless you have studied CS and are well adapted in coding, the general rule is: Get it working first, then optimize if you have to
     
    MossTheTree and Kurt-Dekker like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,009
    Whenever engineering seems too much to tackle, it's always best to see if you can break the problem down.

    What you describe above is by no means simple, as just the different ways all of it could be implemented are complex:

    - does the camera rotate with the player on the asteroid?
    - Do the player's controls rotate as they walk around the asteroid?
    - Does the camera lock to the rotating asteroid?
    - What does the camera do if the player digs down a ways?
    - If the player digs a tunnel into the asteroid, does he walk down on the walls of the tunnel?
    - Which side of the tunnel does she walk down?
    - what if there is a tunnel fork? can he leap to the other side?
    - Does the player bottom out and climb up the other side of the well?
    - Again, what does the camera do when this happens? etc.etc. etc.

    Try to set yourself up for success first: try making a single fixed asteroid in space. Then try out any one of the above ideas (tilemap, bitmap, geometry that you deform, whatever you want to try first) and get ALL of that working properly:

    - get the player maneuvering this fixed-in-place asteroid regardless of its shape or size
    - decide what the camera might do as the player goes around and under the asteroid
    - decide what the controls might do then
    - get them actually digging on the part of the asteroid in front of their shovel
    - get the asteroid changing in response to that
    - etc.

    Absolutely NOTHING above will be done "all at once." Every part of it will be iterative piece by piece, experimentation and refinement.

    Do not consider moving onto floating multiple asteroids that you can leap on and off of until you have 100% of all the walking and digging working in a single static asteroid.

    Again, set yourself up for success, not complex compounding confusion.

    And as Corny said, do not even THINK about optimization. Think about gamejam, gamejam, gamejam, test, test, test, iterate, try, fail, try, learn, try, fail, succeed, layer, the next step on, try, fail, succeed move on,
     
    Last edited: Feb 4, 2023
  4. MossTheTree

    MossTheTree

    Joined:
    Jan 12, 2023
    Posts:
    4
    CodeRonnie and Kurt-Dekker like this.