0 votes

Hi, everyone. I thinks this is my first question on this godotengine.org ).

I am playing around with a simple top down 2D RTS project. I have watched the Stein Codes tutorial. It's very nice. Currently I want to implement movement of units. However, in the Stein Codes tutorial the selection of units is done by left click of a mouse and movement is done by right clicking on some location on a map. The way I want the movement to work is to select a Unit1 by left click, then move the Unit1 by left clicking on a location on a tile map. While the Unit1 is moving I need to be able to select another Unit2 by left clicking and move it to another location. When I select Unit2, Unit1 automatically gets deselected. The Unit1 and Unit2 need to move independently from each other. As far as I know the same thing is done in Age of Empires 2.

The problem I am having at the moment is that while Unit1 moving to some location, if I select Unit2, Unit1 gets deselected but it starts moving to the location of Unit2.

I am using the standard stuff:

get_global_mouse_position()

func _input(event):
    ...

func _on_Unit_input_event(viewport, event, shape_idx):
    ...

This is the physicprocess method:

func _physics_process(delta):
    target = get_parent().get_units_targets()[self]
    velocity = (target - position).normalized() * speed
#       rotation = velocity.angle()
    if (target - position).length() > 5:
        move_and_slide(velocity)

The problem is that the target for all units on the map.

I based my implementation on this sample:

https://docs.godotengine.org/en/3.1/tutorials/2d/2d_movement.html#click-and-move

in Engine by (12 points)

Please log in or register to answer this question.

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 [email protected] with your username.