Make the velocity ZERO when the object comes to rest.

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

In the project the circles are spawned above. They fall down and collect at the bottom. But after some time the circles collected below which are at rest start shaking. How can I stop this jittery motion when the circles are at rest ?
Here is the Project.

:bust_in_silhouette: Reply From: whiteshampoo

I’m not sure if this is what you want, but try this:

func _physics_process(delta):
	var tmp_pos : Vector2 = position
	velocity = Vector2(0.0, 200.0)
	velocity = move_and_slide(velocity, Vector2( 0, 0 ), true, 2, 0.785398, false)
	if tmp_pos.distance_to(position) < 0.15:
		position = tmp_pos
		velocity = Vector2.ZERO
		modulate = Color.red   # \
	else:                      #  > Just for debugging. can be removed
		modulate = Color.white # /
	update()

The objects are not shaking. It just looks like shaking, because the are in between pixels, and thy physicsengine can’t decide where to put teh 1px line, because there is no sub-pixel drawing. You can enable antialiasing for the Line, which makes it less obvious.
You can also try to activate pixel-snap in the rendering options, but thats not the ‘cause’ of the ‘problem’.

Thank you so much. I posted this question a lot of time here; Nobody answered to it. Finally you helped me solve it.

Yasin | 2020-06-06 13:40