godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.48k stars 21.08k forks source link

Positioning a loaded instance on a big gridmap is buggy #58939

Closed SoftDevDanial closed 2 years ago

SoftDevDanial commented 2 years ago

Godot version

4.0-alpha4 , 4.0-alpha1

System information

Windows 10

Issue description

Hi,

So I made a 37x37 floor with gridmap and have a spawn script to spawn instances at a Point3D. In my script, i just assigned the position with the global_transform.origin of the Point3D. Below is my script of the spawner. image

When it spawns, somehow its not spawning at the assign spot. Its consistently spawning at a different position. I already double checked all the scripts and nodes if i accidentally did something wrong but i could not find it. This is happening when i changed the gridmap from 13x13 to 37x37. I suspect it has to do something with adding too many of them.

Below is a console print that i made to check what i assigned. I printed out the position of the point3d and the position of the instance that i assigned in the spawner/point3d script and I printed the position on the _ready function in the spawned instance/characterbody3d image

ps: This is like a tower defense game where the monsters go to certain points using the navigationregion3d

Steps to reproduce

  1. Make a 37x37 gridmap with a floor
  2. Put a Point3D on the 5x5 grid
  3. Create a spawner script to spawn instances/enemies on that point

This is my spawner script

extends Position3D

@export var maxSpawn : int = 10

@onready var timer : Timer = get_tree().root.get_child(0).get_node("Spawner")
@onready var navigation_region : NavigationRegion3D = get_tree().root.get_child(0).get_node("NavigationRegion3D")

var enemy_group
#var is_baking = false # Used with wall detection

# Called when the node enters the scene tree for the first time.
func _ready():

    print("Running navigation mesh bake function")
    pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):

    pass

func _on_spawner_timeout():
    var enemy = load("res://Scenes/Enemy.tscn").instantiate()
    enemy.position = Vector3(global_transform.origin)
    enemy.add_to_group("enemies")
    add_child(enemy)
    print("Position Assigned to Enemy - ", enemy.position , " -- " , "Position of Point - " , global_transform.origin)
    enemy_group = get_tree().get_nodes_in_group("enemies")
    if enemy_group.size() == maxSpawn:
        timer.stop()

    pass # Replace with function body

Minimal reproduction project

Minimal Reproduction Project.zip

Calinou commented 2 years ago

@SoftDevDanial Please upload a minimal reproduction project to make this easier to troubleshoot.

(This should be a complete working project, not just a single script.)

SoftDevDanial commented 2 years ago

@Calinou I have attached the Minimal Reproduction Project. I opened two issues so this zip includes both issues. I will upload to other issue as well

SoftDevDanial commented 2 years ago

Apparently, i forgot that when i add a child to the parent, it takes the origin of the parent. So ther3 is no bug in here.