thatsweeneyguy

  • Mar 30, 2020
  • Joined Mar 12, 2020
  • 0 best answers
  • @Stefan_GameDev said: Also, make sure you haven't got any z-index interfering with the ysort.

    OH MY GOD! Even without the video, that single sentence solved my problem. I had the Z-index set to 1 on both the player and the tree because I was layering them differently before. I figured that if they were on the same index, the YSort should keep them in line. I never thought to just reset them to zero...

    I'm still really new with godot, and just as I thought it would be, this was something super silly that I should have recognized lol

    Thank you so much. This has been killing me for the last few days

  • So, the pivot is where the tree is positioned on its scene yeah? My player and Tree are both placed so the 0,0 point is at the base:

    This doesn't seem to make any difference though. I'm so lost.

  • so would I just need to set the scene's origin at the same time I set its position when the scene is instanced?

    The way my game is built, each tree is generated as a scene at runtime, and in order to get them into the right place, I had to manually position it when it's created. Is there a built-in variable for the pivot?

  • So, I have my player scene and "tree" scene as children of the same YSort node.

    When I run the game though, the layering still isn't working, and my player just walks on top of the trees...

    I have no idea what I'm doing wrong, as I thought all I needed to do was make sure everything was a child of the same YSort node and they'd be sorted.

  • @Z3R0PTR said: You could use layers of tilemap nodes in combination with the Y-Sort node.

    I've accomplished almost the same thing by adding a second sprite to the trees for the higher layer. I just set that sprite's z-index one higher, and boom.

    I was just hoping there would be an easier way of handling it. The Ysort nodes kinda confuse me because wouldn't my Player need to be a child of the same Ysort node as the environment in order for it to sort everything correctly?

  • @TwistedTwigleg said: I have not really used it myself, but I think the Y-Sort node can achieve this effect. If I understand how it works correctly, the Y-sort node should make it where sprites and objects with a higher Y value are drawn behind those with a lower Y value, allowing the character to walk behind the tree.

    I'll look into that and see what I can do.

  • I'm having some trouble with the Z-index. I'm still really new to Godot, though, so this could be a simple fix.

    All I want to do is make sure the trees are drawn behind the character if they're standing in front of it, and above them if they're standing behind it...

  • I've tried various ways to change the spawn position, but no matter what I try, I still can't get the trees to spawn. I thought maybe I wasn't referencing my grass correctly, but when I just tried to instance a tree onto every tile_position in the for argument, it didn't work then either. I'm so confused right now lol.

    Here's an update on exactly what I've got in the script attached to my Tilemap:

    extends TileMap
    
    onready var tree_scene = preload("res://testtree.tscn")
    
        
        func spawn_tree(tile_position: Vector2):
        	var tree = tree_scene.instance()
        	tree.position = tile_position
        	add_child(tree)
        
        func generate_trees() -> void:
        	for tile_position in get_used_cells():
        		if get_cellv(tile_position) == tile_set.find_tile_by_name("Grass"):
        			spawn_tree(tile_position)
        
        func _ready():
        	generate_trees()

    I'm thinking maybe the 'for' argument isn't doing something right, but I can't be sure.

  • Well... that's kind of a duh moment on my part. lol

    So, here's what I have now:


    extends TileMap
    
    onready var tree_scene = preload("res://testtree.tscn")
    
    func spawn_tree(tile_position: Vector2):
        tree_scene.instance(tile_position)
    
    func generate_trees() -> void:
    	for tile_position in get_used_cells():
    		if get_cellv(tile_position) == tile_set.find_tile_by_name("Grass"):
    			spawn_tree(tile_position)
    
    func _ready():
    	generate_trees()

    It's no longer displaying errors, but it still isn't instancing the trees. I feel like I'm probably making another mistake that's obvious to a more experienced godot dev and I'll laugh at how easy it is to fix...

  • Here's what I've got... (This script is attached to my TileMap)

    extends Node2D
    
    onready var tree_scene = preload("res://testtree.tscn")
    
    func spawn_tree(tile_position: Vector2):
    	tree_scene.instance()
    	
    func generate_trees() -> void:
    	for tile_position in get_used_cells():
    		if get_cellv(tile_position) == tilemap.tile_set.find_tile_by_name("Grass"):
    			spawn_tree(tile_position)

    It's returning an error saying "The method get_used_cells() isn't declared in the current class"

    I wasn't 100% on what you meant by adding the spawn_tree func, but I hope I got it there, and the GRASS_TILE_INDEX detail was fuzzy. The language I'm used to is a variation of C++, but it's got so much stuff built-in that I feel like coming over here to a "real language" might be a bit more of a learning curve than I foresaw =)

  • I want to loop through the world and find any "Grass" tiles on my Tilemap. I then want to perform an action on each valid tile, like instancing a new scene.

    What I'm trying to accomplish is creating any trees, rocks, etc in the world at runtime. This let's me build the background map, and generate a new environment each playthrough.

    I'm new to Godot, recently migrating from BYOND. Over there, this would be pretty straightforward. Just tell the client that for every grass in the world, place a tree if a probability threshold is met:

    World
    	GenerateTrees()
    		for(var/turf/grass/g in world)
    		    	if(prob(10))
    		    		var/obj/tree/t = new(obj/tree)
    					t.loc=locate(g.x, g.y, g.z)

    I have no clue how I'd go about doing something like this with GDscript, though... can anyone help me out?

  • Wow. Just wow. You've definitely got a talent!

    I just migrated to Godot and am working on my first big project. I'll be using many of the "Fantasy" tracks for background music, and will be giving credit where credit is due.

    Thank you so much for making this amount of content for public use!