0 votes

So, I have a KinematicBody2d of a soldier and when I press, let's say, ui_select a new soldier is created. I wrote this script for the root node, but it doesn't seem to work.

func _input(event):
if event.is_action_pressed("ui_select"):
    var soldier = get_node("Soldier").duplicate()
    soldier.position = Vector2(get_viewport().size.x/2, get_viewport().size.y/2)

What is the proper way of doing this?

asked Jun 5, 2019 in Projects by da_dev (32 points)

1 Answer

0 votes
Best answer

Save the Soldier as a scene and instance it:

const Soldier = preload('res://Soldier.tscn')

var soldier = Soldier.instance()
answered Jun 5, 2019 by Dlean Jeans (3,893 points)
selected Jun 9, 2019 by da_dev
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.