Move to click - DON T WORK!

Godot Version 4.2[
Move to click Dont work ! 2D movement overview — Godot Engine (stable) documentation in English dont work !
Simple test X coord.

extends CharacterBody2D
var speed = 20
@onready var target_position = Vector2.ZERO
var click_position
 
 
func _physics_process(delta):
	

	if Input.is_action_pressed("click"):
	
		click_position = get_global_mouse_position()
		
		print("click_position.x", click_position.x)
		print("position.x", position.x)
		
		if (click_position.x>position.x):velocity.x = 5 * speed
		if (click_position.x<position.x):velocity.x -= 10 * speed #The sprite comes back with strong jerking - X coord
		
		move_and_slide()

I keep going back to the documentation for this. I just can’t seem to remember every important snippet. A class reference just in case; https://docs.godotengine.org/en/stable/classes/class_viewport.html
But, what I see going on is pretty classic. You have to get the size

get_viewport_rect()

It’s used as

var screen_size

And a set of

func _process(delta):
var velocity = Vector2.ZERO # The player’s movement vector.
if screen_size == x :
velocity.x += 1
if screen_size == x :
velocity.x -= 1
if screen_size == y:
velocity.y += 1
if screen_size == y:
velocity.y -= 1

Also, verbadum; literally not what the documentation says.

extends CharacterBody2D

var speed = 400

var target = position

func _input(event):
	if event.is_action_pressed("click"):
		target = get_global_mouse_position()

func _physics_process(delta):
	velocity = position.direction_to(target) * speed
	# look_at(target)
	if position.distance_to(target) > 10:
		move_and_slide()

I just checked. You just have to add input called CLICK. It’s literally just Left Mouse Button.
However the Spites in this case like to be ZEROED. Otherwise it will just add to the current Values.

OK ! I am unerstand ! need in 2D scene set 0 coord for NODE 2D

  • This mouse coord - local position !

Need set center in sprite - or take other coord

I’m not sure about the entirety of your comment.
Off the top of my knowledge.
! is used to HIGHLIGHT operator for a later MATCH.
You wouldn’t have enough time to condense this practically. Godot 4 takes care of this automatically. And, future feature releases might develop even further conditions.
FYI! Godot uses Godot script to comment on itself in the basic UI functions similar to Godot script.