Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | peck |
So i was watching this tutorial https://www.youtube.com/watch?v=Q2iWDNq5PaU&ab_channel=xen-42 and i keep getting this error godot error invaild call. nonexistent function ‘set_chunk_position’ in base ‘Spatial’
ill past my code so where i am trying to run the fuction
extends Spatial
var chunk_scene = preload(“res://chunck.tscn”)
var load_radius = 5
onready var chunks = $Chunks
onready var player = $Player
var load_thread = Thread.new()
func _ready():
for i in range(0, load_radius):
for j in range(0, load_radius):
var chunk = chunk_scene.instance()
chunk.set_chunk_position(Vector2(i, j))
chunks.add_child(chunk)
load_thread.start(self, "_thread_process", null)
func _thread_process(_userdata):
while(true):
for c in chunks.get_children():
var cx = c.chunk_position.x
var cz = c.chunk_position.y
var px = floor(player.translation.x / Global.DIMENSION.x)
var pz = floor(player.translation.z / Global.DIMENSION.z)
var new_x = posmod(cx - px + load_radius/2, load_radius) + px - load_radius/2
var new_z = posmod(cz - pz + load_radius/2, load_radius) + pz - load_radius/2
if (new_x != cx or new_z != cz):
c.set_chunk_position(Vector2(int(new_x), int(new_z)))
c.generate()
c.update()
and when the function is
func set_chunk_position(pos):
chunk_position = pos
translation = Vector3(pos.x, 0, pos.y) * Global.DIMENSION
self.visible = false
thanks and sorry if its a bit long