Drawing after the mouse VS drawing after the character body following mouse

Godot Version

v4.2.1.stable.official [b09f793f5]

Drawing after the mouse VS drawing after the character body following mouse

Problem

Okay. I’m making game about drawing tree with mouse. Somewhere at the some point I’m doing this thing:

	if event is InputEventMouseMotion && pressed:
		if can_draw:
			current_line.add_point(get_global_mouse_position())
			new_curve_path.add_point(get_global_mouse_position())

As result I’m getting tree looking like this:


Troubles started when we tried to limit area of drawing tree. First our attempt - use area2D and enter/exit signal failed. Reason - one frame offset between signal emitting and processing which can’t be eliminated. Fast mouse movement - and you out of bounds for one frame.

After that we realized - if you want to put brush into the box you need the box. So, I’ve created four invisible StaticBody2D walls and turned my brush into CharacterBody2D. Here is related part from my brush.gd:

func _physics_process(delta: float) -> void:
	...
	previous_mouse_position = get_global_mouse_position()
	var motion = (get_global_mouse_position() - global_position) if is_mouse_follows_brush else Vector2.ZERO
	move_and_collide(motion)
	...

And thing I’m doing with lines now looks like this:

	if event is InputEventMouseMotion && pressed:
		if can_draw:
			current_line.add_point(brush.global_position)
			new_curve_path.add_point(brush.global_position)

And for some weird reason my beautiful smooth tree turns into this:


And I don’t have event slightest idea why. Thing I understood so far: difference between smooth and distorted are difference between get_global_mouse_position()) and brush.global_position in code part cited above.

Things I’ve tried so far

It looks like some problem with joint mode of Line2D but no, I’ve checked it:

	current_line.joint_mode = Line2D.LineJointMode.LINE_JOINT_ROUND
	current_line.begin_cap_mode = Line2D.LineCapMode.LINE_CAP_ROUND
	current_line.end_cap_mode = Line2D.LineCapMode.LINE_CAP_ROUND

Also, tried to play with all this joint parameters like sharp_limit. Tree looked little better but still was distorted.

Second thing I’m tried - use move_and_slide instead of move_and_collide. Without any success. It looked the same.

Question

What the heck is wrong with tree painted by brush positions?