0 votes

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 moveandcollide() 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

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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.

by (10,610 points)
selected by

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

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.