How to make laws for a world instead of giving codes to characters?

I wanted to make laws for a world, like the law of gravity by mass, and a law of “if object touches flat base, then start idle animation”. This are some examples and I want to make more, so I needed a help, since, I’m just a starter in godot engine.

The laws supposes to affect everything that I drag to the world game (scene) and it is to avoid making same codes for every object that I create.

I think that what you’ve described is how programming works in general? :sweat_smile:

Maybe you could try coding an object, called WorldEntity and make other entities inherit from it, so they all benefit from the same “Laws”

1 Like

Thanks for the answer. I have a doubt that is, if one object that is inside the World Entity Group is duplicated, will it be analyzed as separated objects or it will be received to the world law, the same effect [as the law] if ‘one of them’ is effected by the ‘law’? Still need to test it, though.

You might want to look into ECS. Basically your laws would be Systems.

Godot is not ECS based though, but it might help to read a bit into how ECS works and see if you can apply some of those patterns in Godot.

If you don’t mind using pre-release software, then you should check out Godex. It is based upon Godot.

1 Like

Thanks for taking your time to help. I see, Entity Component System; it should actually help a lot to assimilate the laws of a world. Again, thanks for the help.

1 Like

Its late here so maybe I’m misunderstanding something, but why not just fake it by making a singleton?

You can then just access those variables(laws) from your singleton in your various game object scripts.

As long as the variables aren’t changed by any game object, they are effectively ‘laws’.

1 Like

why not just fake it by making a singleton?

Singletons must be used to store data globally or to globally call/connect to/from signals.
Could they work to store data, like the “laws” they proposed? Yes.

But you see, singletons on their own are not the solution, as they should never control Objects directly.

They precisely stated:

The laws supposes to affect everything that I drag to the world game (scene) and it is to avoid making same codes for every object that I create.

This means that they’re thinking of code re-usability to avoid repetition.

You see, the problem were not the laws themselves, but how to make all the objects be affected by these laws in ‘the same way’.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.