0 votes

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

Godot version gles3
in Engine by (17 points)

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

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

1 Answer

0 votes

just use global_position everywhere :)

by (7,925 points)

Yeah im going to go through and re do it with global_positins thnks :)

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.