The whole world is moving with my character, and I'm not sure why.

Godot Version

4.4.1

Question

The whole world is moving with my character, and I’m not sure why.

So I’ve created a small game for my first Gamejam. It’s a game where you play as a worm, moving upward on the screen to collect fruit and avoid obstacles.

Near the beginning of my project, I noticed something was oddly out of sync, and the worm wasn’t moving in line with the background or anything else. (The worm is a Node2D that I’m moving manually, rather than a Character2D, though when I recreated it as a Character2D it seemed to have the same issue, so it’s not even a physics thing as far as I can tell) I ‘fixed’ this by just… attaching all the important things to the worm directly.

But now, I’m finding that the more I add the harder and harder it is to keep it consistent (especially with particle effects), and I’d like to understand where it went wrong and how it’s out of sync in order to make it work correctly.

It’s important to note that it’s not completely moving as one big object. When it first went wrong, I noticed the worm was moving like… 10% too fast compared to everything else, which made it look like it was sliding around wrong. Now, everything else is moving at about 10% of the worm’s speed so it can keep up and make it look like it’s all moving at the correct speed.

As far as I can tell, this is my only code for making the worm move:

func move(delta):
direction = Input.get_axis(“Left”, “Right”)
position.y -= speed * delta
head.rotation_degrees = move_toward(head.rotation_degrees, head_tilt * direction, speed * 10 * delta)
position.x = move_toward(position.x, position.x + (speed * direction / 50), delta * speed)
if position.x > 260:
position.x = 260
head.rotation_degrees = 0
if position.x < -260:
position.x = -260
head.rotation_degrees = 0

Everything else–the fruit and obstacle spawners, the camera, it’s all just attached to the worm, moving with it that 10% that I can’t figure out where it’s coming from to keep it in sync.

It also doesn’t matter whether I use global_position or just position, it doesn’t seem to change anything.

It feels as if there are two movements for the worm–one movement that is how I want it to move, an an extra 10% of movement that’s just tacked on for no apparent reason that affects everything, and I’m not sure why.

Let me know if there’s anything else I can share or add to make this easier to diagnose! I can attach or share a zip file of the game somehow, if that helps. I’ve been struggling with this all morning, and I’d really love to have it figured out so I can move on to other things.

Thank you!

Can you show us the node hierarchy for your scene?

1 Like

Sure thing! Here’s the nodes for the Worm.

I can only upload one image at a time at the moment, but the World node is literally just the World and then also the Worm as a child to that, since I attached everything else to the worm

If your “Worm” is the player then everything is a child of it, children move with their parents so when the worm moves so does everything else.

Are your level components children of the “world”? If you truly have nothing else in the world then you will have a hard time distinguishing movement.

Yes, everything is technically a part of the worm, basically.
And yeah, everything moving with the Worm is how I ‘fixed’ the initial problem of things sliding around in a really weird way.
I should see if I can send a video of it, let me see…

20250720-0147-25.1063489

This is a fairly low quality video, but I managed to show the effect with a duplicate that decoupled everything from the worm. Now the Worm is on the world with the background, and the World isn’t moving, but when the Worm moves (both up and left and right) it goes faster than it should, making this weird ‘sliding’ effect. It’s Tail is a Line2D that has new points made at the front where the head is, and the oldest points deleted in order to ‘move’ it, so those point should be fixed in space where they’re placed, but instead they’re sliding around with the rest of the worm, and I’m not sure why.

Yeesh, sorry, that video was REALLY bad

I got a better one with a link here: https://imgur.com/a/XLspw8R

1 Like

I see, looks great! The moving faster diagonally is probably happening because your direction isn’t normalized, so travelling (0, 1) forwards ends up as a total of 1 speed, but moving (1, 1) diagonally is 2-ish speed.

Since you always want to move upwards your equation may look like this, first making a vector for direction then normalizing it.

var direction := Vector2(Input.get_axis("Left", "Right"), 1.0).normalized()
position += direction * speed * delta