我正在为实体系统添加物理,并对ECS的系统部分感到困惑。ECS(实体组件系统)中的交互系统?
例如,在非ECS项目我可能有这样的事情:
function updatePhysics()
foreach(thisRobot in robots)
thisRobot.move()
foreach(otherRobot in robots)
if(response = thisRobot.isColliding(otherRobot))
thisRobot.resolveCollision(response)
但是在ECS项目,我想有一个PositionComponent和VelocityComponent工作以及一个一个MovementSystem在PositionComponent和ShapeComponent上运行的CollisionSystem。其结果是这样的:
MovementSystem
function update()
foreach(entity in entities)
this.move(entity)
CollisionSystem
function update()
foreach(thisEntity in entities)
foreach(otherEntity in entities)
if(response = this.isColliding(thisEntity, otherEntity)
this.resolve(thisEntity, response)
的区别是在非精英版的运动和碰撞交错其中,作为ECS版本它们分隔。在实体系统中是否有正常的模式来模拟这种行为?我知道ECS的要点是摆脱继承,但是可能让MovementSystem和CollisionSystem成为更一般的物理系统的一部分,该系统会在单个实体上调用其他系统更新函数,而不是每个系统维护自己的循环?
在你的循环中,你有4和5分开。我的问题是针对如何交错这两个系统。 – zorqy