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

asked Apr 22 in Engine by mrsandman (16 points)

1 Answer

0 votes

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

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

answered Apr 22 by kidscancode (5,626 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 How to use this Q&A? before posting your first questions.