KinematicBody2D Gradual Movement To Mouse Click Co-ordinates

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

Hello everyone,

I am trying to build a 2D RTS game with Godot 3.

I’ve tried several things but I have zero idea of how to move the KinematicBody2D units that I have to the specific mouse co-ordinates when an area is clicked. I have implemented selection and I tried really hard, hours and hours, I can’t get the movement done :confused:

This is the unit script without any of my movement attempts shown:

extends KinematicBody2D

var selected = false setget set_selected

# Stats
var max_health = 100
var hp = max_health

func set_selected(value):
	selected = value
	$HealthBar.visible = value

func _ready():
	set_selected(true)
	pass

func _process(delta):
	$HealthBar.update_health(max_health, hp)


func _on_input_event(viewport, event, shape_idx):
	
	print(event.position)
	
	if not event is InputEventMouseButton:
		return
	
	if event.button_index == BUTTON_LEFT and not event.is_pressed():
		self.set_selected(!selected)

Thank you so much in advance - I will be thankful for any help received.

:bust_in_silhouette: Reply From: kidscancode

You may find this tutorial helpful: 2D Movement Overview.

It demonstrates the click-to-move style of movement using a constant velocity.