The title pretty much says it all. I have a card game where the player is one card that has to battle the other cards. All cards are character2D node scenes, each with a collision shape and several raycasts.
When I instance the NPC cards, they spawn at the expected locations. However, when I instance the player card, he spawns with a small x_offset from the place where I want him to span. I have the impression this has nothing to do with my code because the spawning location of the player card changes when I rearrange the nodes of the player scene. For instance, it changes if I shift the collision shape to be a children of the player sprite. Thus, if the arrangement is:
Character2D
----CollisionShape
----Sprite2D
The spawning position will be different than if I organize it with the collision shape as a child of the sprite 2D node:
Character2D
----Sprite2D
--------CollisionShape
The spawning location also changes significantly when I change the size of the collision shape.
I find all this really confusing. Does anybody know why it could be happening?
Collision shapes only work as a direct child of the CharacterBody2D, or other collision-type nodes. The second example has no working collision, you should see a warning icon on both CharacterBody2D and CollisionShape2D expressing this.
Thanks pdhales72 and gertkeno. I understand what you both say and I appreciate it.
pdhales72, showing the collision shapes in debug mode does not really help. They show exactly where they should be in relation to the parent node. The issue is that the parent node is displaced from where it should be, and that changing the collision shape (its shape or its parent-child relation) makes the parent node spawn at different locations.
I think I should have presented my question more succinctly. The question is:
Why does adding a collision shape to my character change its spawning position?
Depends on your code and how your collision is set up. It sounds like your player is being nudged because it spawned inside another collision shape, or was programmed to spawn incorrectly, maybe the player’s sprite and collision shape are offset from the CharacterBody.
Let’s start with what does your main scene look like, can you screenshot where your player is when they spawn, with collision shapes visible?
Thanks gertkeno, this seems to help. I am pretty sure player sprite and collision shape are correctly placed because I changed the collision layer of the player scene and the problem no longer appears (I lose the collision shape functionality though, which is a problem).
Clearly my character is being nudged sideways for some reason that has to do with its collision shape. It does not seem to spawn within another collision layer, but I think your advice puts me on the right track.
I have to go now. I’ll try to share a screenshot later.