How to [best] implement biological cells that divide and populate 3D space in Godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toblin

Hi forum,

I’ve been spending some time now (2-3 days full time) on trying to understand the Godot engine. Still I’m having real troubles with the basics. One contributing reason (I think) is that I’m not trying to make a “traditional” game.

Project description

Here’s what I want to do: I want to create a software (with a GUI) that creates geometric 3D shapes based on evolutionary principles. The user should be able to see the shapes in 3D, generate new shapes (with random genes), and to breed existing shapes by combining existing shapes, with simple clicks on the GUI.

On a conceptual level I have a clear idea on how to proceed. I will closely mimic cells and cell functions. Hence there should be some kind of cell object that has genes, morphogens (internal chemicals), as well as mechanisms for 1) communicating with other cells, 2) cell division, and other functions, that are based on the genes and morphogens. The creation of a new shape should start with a single cell that divides to form a mature shape consisting of many (~10^5 to ~10^6) cells.

The cells should have simple physics defined - such that they stick together. No gravity is required.

Godot implementation

I have a great deal of confusion on how to implement the above in Godot. I’m most familiar with Python, and am having troubles with instantiation, among other things. My aim is to program it all through GDscript.

I think I understand how the collision bodies and the 3D nodes interplay based on tutorials. One has to define shapes that can be seen together with shapes for physics and collision management, where one defines their relation through the node tree.

I’m guessing that the following could be a correct way to proceed with the 3D spatial and physics parts:

# Main scene: notation <Node name> [ <Node type> ]
State [Node]
---- Spatial [Spatial]
-------- SpaceCell [SpaceCell.tscn]

# SpaceCell.tscn
SpaceCell [Area]
---- CollisionShape [<---]
---- CGSSphere [<---]

I’m thinking that I need SpaceCell as a scene (as per above) in order to instantiate it in the main scene (if this is not necessary or there is a better way - please let me know).

Assuming that the above is a good way to proceed, the question is: how do I implement the “biological cell” that has the morphogens, the genes, and all related “biological behavior”? Should I make it a node somewhere? Should I make a custom class that is then instantiated somewhere?

I have tried implementing a GDscript with a custom class through:

class Cell:
    var gene

	func _init():
	    gene =

class Gene:
	var a

	func _init():
		a = 1

Which I then make into a variable in a script attached to the SpaceCell which I then use to instantiate the cell instances as properties on the SpaceCell objects:

 extends Node
 var cellmod = preload("res://")

 func _init():
     var cell =

I’m then thinking to have the cells at the “space” level, whereby the Spatial node in the main scene has a script attached that specifies:

extends Spatial

var SpaceCell = preload("res://SpaceCell.tscn")
var spacecells = {}

func _ready():
	spacecells[1] = SpaceCell.instance()
	print("spacecells[1].cell = ", spacecells[1].cell)

such that it has a dictionary that keeps track of all the space cells in existence.

I try to populate the dictionary in the _ready() function just to test the project setup. When I try to access the cell property through spacecells[1].cell however, it tells me:

"Invalid get index ‘cell’ (on base: ‘Area (’)

I’m presuming because I’m trying to access the property incorrectly, and not because it doesn’t exist (I’m thinking that it should have the cell property due to the _init() function in the SpaceCell script)


The above is a mouthful - I grant you. What I’m looking for is the following:

  1. Tips /thoughts on how to structure the project: how should I best do so, am I on the right track, etc
  2. Meta-comments on whether or not the project is possible to implement, and whatever else comes to mind
  3. How do I access the cell property of the SpaceCell.instance()?

Consider posting on Reddit: Reddit - Dive into anything
More discussions going on there.

Dlean Jeans | 2020-02-25 14:25

Considered and done =). Should I remove the thread from here?
Reddit - Dive into anything

toblin | 2020-02-25 14:38

This is an extremely lengthy question so yeah, lower chance to getting “answered” here. You could leave it but in general QA is for simpler questions.

Zylann | 2020-02-25 20:13