0 votes

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 :/

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():

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

func _on_input_event(viewport, event, shape_idx):


    if not event is InputEventMouseButton:

    if event.button_index == BUTTON_LEFT and not event.is_pressed():

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

in Engine by (16 points)

1 Answer

+1 vote

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

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

by (21,309 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.