Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | 1tokenblackguy |
so i have a Level Scene and i have a node for building and vehicles also a button that spawns a building and another button that spawns a vehicle.
when i click the button it .instances() the building fine and i can get the vehicle button to spawn the vehicle at the .positon of the of the building. however in the building scene i have put a position2d node at 50, 50
my proble is i cant seem to get the script in the level scene to spawn the vehicle at the position2d node .position
extends Node
const Refinary = preload("res://Assets/Refinery.tscn")
const Harvester = preload("res://Assets/Harvester.tscn")
var REFINARYSPAWN = false
var HARVESTERSPAWN = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func _process(delta: float) -> void:
if REFINARYSPAWN == true:
$HUD/RefineryButton.disabled = true
$HUD/SpawnHarvester.disabled = false
elif REFINARYSPAWN == false:
$HUD/SpawnHarvester.disabled = true
func _on_RefineryButton_pressed() -> void:
var i = Refinary.instance()
$Buildings.add_child(i)
i.position = Vector2(400,400)
REFINARYSPAWN = true
func _on_SpawnHarvester_pressed() -> void:
var i = Harvester.instance()
var b = 34
$Vehicles.add_child(i)
i.position
the building sceen is and area2d with a sprite colision shape and a position 2d node.
if anyone could help me figure this out that would be great
So ive updated the code and i can get the node to spawn at the Position2d node however
it spawns at level 50 ,50 not at 50 , 50 off the instanced building
updated code
func _on_RefineryButton_pressed() -> void:
var i = Refinary.instance()
$Buildings.add_child(i)
var b = i.get_node("RallyPoint")
Rally_Point = b.position
print(Rally_Point)
i.position = Vector2(400,400)
REFINARYSPAWN = true
func _on_SpawnHarvester_pressed() -> void:
var i = Harvester.instance()
$Vehicles.add_child(i)
i.position = Rally_Point.position
1tokenblackguy | 2022-02-19 13:59
Managed to figure out a way to work it out
func _on_RefineryButton_pressed() -> void:
var i = Refinary.instance()
var b = i.get_node("RallyPoint")
$Buildings.add_child(i)
i.position = Vector2(300,400)
Rally_Point = i.position + b.position
Refinary_Spawn = true
func _on_SpawnHarvester_pressed() -> void:
var i = Harvester.instance()
$Vehicles.add_child(i)
i.position = Rally_Point
1tokenblackguy | 2022-02-20 06:41