Why does "position" not update after move_and_collide()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pmonson11

Potentially noob question, but I am a Godot noob and cannot find what I’m missing.

I have two scenes. A Parent Scene, which can create multiple instances of a Child scene.
----> Child

The Parent Scene can issue “move” commands to the child scenes. This causes the Child scenes to move_and_collide() with a “StaticBody2D” node on the parent scene. The Child scene emits a signal once it has collided with a wall and stopped.

My problem comes from the following code snippets:


print("childs initial position: " + str(childToMove.position)) 
yield(childToMove, "child_done_moving") 
print("childs final position: " + str(childToMove.position))

The output is as follows:
childs initial position: (192, 192)
childs tiles final position: (192, 192)

I see the child scene moving when I play it. It very clearly doesn’t have the same position.
I’ve checked the global_position, and it’s the same story. What am I missing?

The following is the child code that I think is illuminating.

signal child_done_moving
var velocity : Vector2 

func _physics_process(delta):
     var collide = $KinematicBody2D.move_and_collide(velocity * delta)

          velocity = Vector2(0, 0)

The following is the Node structure of the scenes:

|—> TileMap

|—> CollisionPolygon2D

:bust_in_silhouette: Reply From: njamster

You’re moving the KinematicBody2D, but the child-node itself stays in place. Try this:


I’d recommend simply making the KinematicBody2D the root-node of your child-scene.

Thank you so much that worked! It makes so much sense, geez, can’t believe I missed it.

pmonson11 | 2020-02-11 12:47