0 votes

Hi,

I have a project where I am trying to create a player out of several difference scenes (with the player as a simple spaceship, with the main body of the ship as the main Player scene and two engines as separate sub-scenes). The issue is that the CollisionShape2D nodes on my sub-scenes do not seem to function -- only the CollisionShape2D on the main Player scene is interacting with walls created via a TileMap correctly. The PhysicsBody2D Collision Mask layer settings seem to be correct, with the mask for the Player scene and sub-scenes set to be the same.

The CollisionBody2D on the root Player scene is working correctly, it is just the CollisionBody2Ds from the sub-scenes that do not appear to be engaging with the walls. The layout for my Player scene is as follows:

KinematicBody2D (root node / Player scene)
 - Sprite
 - CollisionShape2D
 - ShipEngine_left
 - ShipEngine_right

The "ShipEngineleft" and "ShipEngineright" nodes are instances of another scene, "ShipEngine". The node hierarchy for this scene is:

KinematicBody2D (root node for the engine scene)
 - Sprite (engine sprite)
 - CollisionShape2D
 - AnimatedSprite (displays the "flames" when engaging the engine)

All of this is working (ship flying correctly, engines animated correctly, entire ship rotating together correctly, etc) except for the CollisionShape2Ds on the ShipEngine sub-nodes. The CollisionShape2D on the main ship body/Player scene is detecting and handling basic collisions with walls correctly, but the engines are passing right through walls and the entire ship does not stop/bounce off until the main body's CollisionShape2D hits the walls. Is there any way I can keep the CollisionShape2Ds on the child scenes, instead of adding those CollisionShape2Ds to the root Player scene? Or does Godot require that all collision shapes be in the Player's root node?

In my searching for an answer, the closest thing I found was the following issue on github, which is now marked as closed...
https://github.com/godotengine/godot/issues/2314

Any advice would be greatly appreciated!

Godot version: 3.2.1.stable.official
Game type: 2D
Render engine: GLES3
Development platform: macOS (High Sierra)

asked Jun 25 in Engine by DashRantic (15 points)

Very wild guess:

Maybe you need joints to connect the bodies together.

Joints don't appear to work with KinematicBody2D.

can you provide your project-folder?

2 Answers

+1 vote
Best answer

the child Bodys are not moved with moveandslide() or
moveandcollide.
Therefore no collision.
Add the CollisionShape2D to the Player.

You can copy them in your Player script.

func _ready():
for child in get_children():
    if child is KinematicBody2D:
        var id: = self.create_shape_owner(self)
        var shape:Shape2D = child.shape_owner_get_shape(0,0).duplicate()
        self.shape_owner_add_shape(id,shape)
        self.shape_owner_set_transform(id,child.transform)  
answered Jun 28 by brainbug (268 points)
selected Jun 30 by DashRantic

Thanks, I ended up doing this and is seems to be working :)

0 votes

Have you check the layers and mask ?

answered Jun 27 by Jorge (198 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.