Trying to understand how to use ECS correctly, as in, the "data model" for want of a better term.
There is, of course, entities, components and systems and I'm hoping an example will make this easy to understand. I'm a bit of a drag car fan so want to make a drag race game. Will involve reaction times but also starting with a basic drag car and building up modules so that the car gets better. Bit of a meta-game to it I guess.
I think my 'data model' will be this:
- two cars racing down a straight track simultaneously.
- the cars will have bits that make it perform better
- those bits will be "common" in the sense that a super-charger on one car will perform and behave the same on any other car.
If I have an entity called "car" and an entity called "super-charger" then I can link the two together in a table that belongs to 'car'. Yes?
The super-charger will have a neat ability to multiple acceleration by 1.5. Is that a component?
And if "motion" is something that happens to the car, but is influenced by the super-charger then ... idk. How to unpack all that? (and haven't even mentioned 'system' yet).
How to think the ECS way?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to think the ECS way?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: How to think the ECS way?
For example
the entity car:
where
So on the adding/removing of modules recalculate parameters as
What is ECS?
the entity car:
Code: Select all
car = {
x=x, y=y, vx=vx, vy=vy, -- just position and velocity
baseMass = 100,
baseForce = 100,
modules = {superChargerModel3, lightAlloyWheelsMk3},
}
car.mass = car.baseMass
car.force = car.baseForce
car.acceleration = car.force/car.mass
Code: Select all
superChargerModel3 = {
forceFactor = 1.2,
mass = 3,
type = "supercharger", -- check that you cannot have two same type modules
}
lightAlloyWheelsMk3 = {
mass = -8,
type = "wheels", -- check that you cannot have two same type modules
}
Code: Select all
car.mass = car.baseMass
car.force = car.baseForce
for i, module in ipairs (car.modules) do
if module.mass then
car.mass = car.mass + module.mass
end
if module.forceFactor then
car.force = car.force * module.forceFactor
end
end
car.acceleration = car.force/car.mass
Re: How to think the ECS way?
What you're experiencing is the completely unnecessary complexity of components (i.e. what value/functionality belongs where). darkfrei's example is pretty simple because it doesn't use components and just puts everything on the entity. In an ECS the "car" should likely be a component. You can think of entities as just being containers for components. A car would not an entity, but rather, and entity could be a car (among other things).
Do you have a good reason to use an ECS?
Do you have a good reason to use an ECS?
Entity Component System.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 7 guests