Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Procedural Mesh and Gradual Change in Shapes for Evolving Bodies

Discussion in '2D' started by PedroHeck, Mar 25, 2022.

  1. PedroHeck

    PedroHeck

    Joined:
    Jan 27, 2019
    Posts:
    11
    Hey there! I'm very new here and I'm currently learning Unity to develop an evolution simulation I've been wanting to do for a long time.

    Quick summary: the 2D simulation will contain cell-like organisms that can have random shapes and that are able to evolve their body morphology over time through mutations and reproduction.

    They can also evolve many other characteristics, but it's the body one that I'm struggling with. Here's the thing: I want them to be able to evolve body parts that aren't scripted, and that can actually interact with the environment (therefore it wouldn't be only visual). The organisms live in a fluid world, and if by chance one has a mutation that gives it a wiggly "tail" of sorts, I want to have an actual advantage (could be speed wise, for example).

    That said, here's my question: how can I make procedural shapes that can be changed gradually? For example, if organism A has a speed of 2.55 u/s (units per second), it's descedents could, by chance, have 2.54 u/s (or 2.53, 2.5, 2.62, whatever number it is). What I mean by that is that the change can be gradual, since it is a float number. So how can this gradual change be translated to a shape? I was thinking of making their body shapes after a path with defined points at random positions, and make these positions prone to change (mutations could also add or remove points in this path). Since I want them to look organic, their shapes should be curvy, and not pointy (meaning that, for this approach, bezier curves would define their body path.

    To make this even harder, since they're cell-like organisms, after the shape is defined I'd want it to be, well, cell-like. By that I mean have a soft body behaviour, or any other type of physics behavior that makes them not so rigid.

    But I don't know if anything I said is possible in Unity. Is there a way to describe (and change) a given shape in code so that it can be tweaked little by little? Or is there any other better approach for what I want?

    Thank you in advance. I hope someone sees this.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    All of this is totally possible. I suggest you don't even think about speeds or sizes or anything like that and just use 100% uniform spheres moving around and get the entire evolution and/or fitness criteria working from a logical standpoint.

    That alone is a massive lift. There's no sense worrying about shapes and sizes and presentation until you have the core engine defined and operating. If it moves uniform spheres around, great, if not, just make it output to Debug.Log() until you have it all working simulator-wise.
     
  3. PedroHeck

    PedroHeck

    Joined:
    Jan 27, 2019
    Posts:
    11
    I get that but the question itself is about how this change in shape can be done. The moving around and the behaviors is something I have the solution for; it's the evolution in morphology that I don't know how to approach.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,947
    Geometry consists of a list of triangles (each being three integer indices) that index into a list of vertices.

    The study of manipulating a manifold (shape) in 3D is called Constructive Solid Geometry (CSG).

    Everything else is up to you.
     
    PedroHeck likes this.
  5. PedroHeck

    PedroHeck

    Joined:
    Jan 27, 2019
    Posts:
    11
    Didn't know about CSG! Thank you for the info, I'll dive into that!