How do you make one node follow the position of a node from another scene?
- Edited
I opened up a similar discussion way back (https://godotforums.org/d/33366-i-want-to-move-the-position-of-one-node-to-another) and I tried to go through it, trying to remember what I got wrong and the proper advice (it's been a while since I revisited this project), but if it's any help this is the up to date version of this project right now
NJL64 Change the collision number
I'm not sure how setting velocity to 0 fixes the issue or how to implement that, where to put it, or who's velocity. Sorry, I'm just kind of confused.
- Edited
NJL64 I'm not sure how setting velocity to 0 fixes the issue or how to implement that, where to put it, or who's velocity. Sorry, I'm just kind of confused.
Set body.velocity
to zero. Since body.velocity
is a vector, you need to set it to zero vector value as @kuligs2 suggested, not to scalar 0
value. If you're in 2D it needs to be Vector2(0, 0)
or Vector2.ZERO
. Once you have that sorted out, assign the container's global_position
to body.global_position
. Eliminate all other code that messes with body's velocity or position (global or local).
Doing the above should result in enemy being glued to the position of the container. This is a simplified version of what you ultimately want to achieve but in coding we often first implement a simpler version of the solution (sorta like a rough sketch), make sure that it works properly, and then proceed to gradually upgrade it into more finessed versions.
So first do the simple gluing, make sure that it works and that you understand how and why it works.
- Edited
This makes the body stop and remain still where it is when making contact with the Area2D:
This, makes the body fall through the floor:
Maybe, I'm misunderstanding.
*I can see I posted the wrong screenshot for the first pic. Sorry.
NJL64 Yes,collision layer/mask is what caused to rise.The collision number of different objects can be set to different.
xyz That's just how the code is called. "bottom_checker" is the Area2D. It's connected with the "body_entered" signal.
When the enemy/object enters the Area2D body, that's when the code to have the enemy node (body) move in to the container node ($EnemyContainer) and stay there is called. That's what I'm trying to figure out.
It's not the Area2D that's the problem (I think). When it makes contact with the enemy, the code is called, but it's the code in my function that I'm struggling with.
I apologize if I'm not communicating myself well.