Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Agentfox |
Hi!
I’m building an RTS game where there’s a main, large scale map, where players command armies, and then when 2 armies collide it loads a battle in a small-scale battle simulator with a map corresponding to their location on the big map, kind of like Star Wars: Empire at War.
So I built the battle loader and it worked fine, but then I wrote a script for it to instantiate units depending on the armies and the navmesh completely broke.
I tried commenting out the script, and manually putting a single unit in the Battle_Loader scene and it worked, but instantiating them again did not.
I’ve double and triple checked the script, but here it is anyway:
extends Spatial
onready var Unit = preload("res://Unit.tscn")
var player_allegience = "Faction 1"
var units_to_spawn = {}
var units_instances = {}
var enemy_units_to_spawn = {}
var enemy_units_instances = {}
func begin_loading():
spawn_units(units_to_spawn)
pass
func spawn_units(units):
for unit in units_to_spawn.size():
# unit types
if units_to_spawn[unit + 1] == "recon":
var _unit = Unit.instance()
get_node("Navigation").add_child( _unit, true)
_unit.type = "recon"
_unit.allegience = "Faction 1"
units_instances[unit + 1] = _unit
for enemy_unit in enemy_units_to_spawn.size():
# enemy unit types
if enemy_units_to_spawn[enemy_unit + 1] == "recon":
var _enemy_unit = Unit.instance()
get_node("Navigation").add_child(_enemy_unit, true)
_enemy_unit.type = "recon"
enemy_units_instances[enemy_unit + 1] = _enemy_unit
pass
I’m not sure what’s going on here, but if anyone could help that’d be great!
Edit: I also noticed that while instantiating AND using a manually created unit, they both break, including the one unaffected by script
(sorry if the indents are weird, it didn’t paste correctly)
This looks to be written in C#? My question is, would you happen to know how to write it in Godot format? I’ve been looking everywhere for a script that will allow me to spawn something without having manual input from the user. (Key press etc etc)
EtrnlFlux | 2019-04-19 15:46
That isn’t c#
MmTtDeveloper | 2019-04-20 15:52