flame
flame copied to clipboard
PositionComponent should maintain its location when transferring to another parent
When component A is transferred from parent P1 to parent P2, we should preserve its global coordinates so that this transfer of ownership wouldn't cause the component A to "jump".
For example, suppose A is an arrow, and P1 is the world. As the arrow makes collision with an unfortunate NPC P2, we want to transfer the ownership of A to P2 so that visually it would become stuck in NPC's forehead. However, we want the arrow to remain physically in place during the transfer so that it sticks exactly at the point where it hit the enemy.
Another example: in a card game you pick up a card from the deck in order to drag it somewhere else on the field. When the card is picked up, it must be moved to a special transparent top-most layer, so that when dragging it wouldn't accidentally go underneath other cards on the field. Then, when released, it would have to be transferred into the component over which it was released. All these transfers of ownership should be completely invisible to the player, and visually the card should not change its position during the transfer.
I think this would make sense as an optional option, but not the default. Maybe a flag to the changeParent method?
In many 2D games things do jump and if the user has set a local position for something it should be maintained, imagine something like swapping a weapon from one character to another, then the weapon shouldn't still be on top of the first character.
I imagine you could kill an NPC, who drops a sword on the ground, then you pick it up and it goes either in your inventory or maybe directly into your hand -- but in any case you'd have a logic for where to place the sword on your character's sprite. So that logic would adjust the sword's position after the mounting, and it wouldn't care what the sword's coordinates were before.
And even if there is a game with peer-to-peer sword exchange, some adjustment of coordinates would still need to take place in order to account for different sizes of characters and their hand positions.
Do you have another example maybe?
Here's another example for my use-case: a world that is split into several areas: a forest, a desert, mountains, etc. As your characters crosses from the Forest into the Desert, you want to transfer its ownership to the Desert component - but obviously you want this to be transparent to the user.