The issue was originally posted on the forum.
I tracked the bug down, here is the scenario:
- Create an entity with Collision component and place the entity somewhere (x != 0, y != 0)
- Clone the entity; here is what happens:
- All of the original enitity's components get added to the cloned entity
- All of the copy-by-value properties (primitive types like numbers) get copied to the cloned entity (except special ones like the entitiy id)
- The collision hitbox of the cloned entity is wrongly offset by (-originalEntity.x, -originalEntity.y)
The problem occurs because the x, y of the original entity get copied to the cloned entity after the Collision component was added to the cloned entity.
Internally, the Collision component attaches it's hitbox to the entity, so that it moves alongside this parent entity. The problem is the hitbox's initial position is wrong and any later x/y changes through attach method are relative. That gives us a constant offset between the cloned entity and its hitbox (-originalEntity.x, -originalEntity.y)
The issue was originally posted on the forum.
I tracked the bug down, here is the scenario:
The problem occurs because the x, y of the original entity get copied to the cloned entity after the Collision component was added to the cloned entity.
Internally, the Collision component attaches it's hitbox to the entity, so that it moves alongside this parent entity. The problem is the hitbox's initial position is wrong and any later x/y changes through attach method are relative. That gives us a constant offset between the cloned entity and its hitbox (-originalEntity.x, -originalEntity.y)