#How do I stop generating the grass 2 times
1 messages · Page 1 of 1 (latest)
@export var timer := 500;
var grass = preload("res://grass.tscn");
var x = 1920 / 2
var y = 1080 / 2
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
timer -= 1 * delta;
if timer > 0:
x += 64
var _ran = randf_range(1,3);
if _ran >= 2.5:
y += 64;
if _ran <= 1.5:
y -= 64;
_grass(0);
func _grass(of):
var __grass = grass.instantiate()
__grass.position = Vector2(x,y - of * 64)
add_child(__grass);
The ; everywhere aren't helping, please get rid of them.
It's a timer, time is measured in seconds so make it a float
@export var timer := 500 # int ❌
@export var timer := 0.5 # ✔️
@export var timer: float = 0.5 # ✔️
timer -= delta
if timer > 0.0:
As for the double terrain, check the scene and the globals in project properties, there is more than one node with this script I think.
How simple? If you're thinking a hundred blocks or so it might work, but you'll run into performance issues quite fast if you add too many scene instances.
Thanks, now it only generates it one time, and I am going to rework the timer and remove the ;
This was really helpful.
Yes, it would be over 100 blocks. Is there a smarter way to make it?
Any game which handles large amount of data (e.g. Terraria, Minecraft, Factorio, Noita, etc) is going to require a smart implementation and lots of optimizations. Godot scenes are not particularly light weight. I think a TileMapLayer could get you further, though you'll probably need a custom solution to make something really large
Perhaps create arrays that save the block type and its position. When the player gets near the said position, it just creates the block scene. I'll just do it like I was doing it before to get the hang of Godot, and then start a new project with more optimizations in mind. Thanks