我正在尝试制作一款 2D 游戏,你必须跳过以随机模式生成的障碍物才能获得更高的分数。它有点类似于铬恐龙。我一直在努力解决移动块部分。我所做的任何事情最终都不起作用,或者使程序崩溃
这是我迄今为止尝试过的(gdScript):
func spawn_time():
const OBSTACLE = preload("res://scenes/obstacle.tscn")
var obstacle_spawn = OBSTACLE.instantiate()
for i in range(4):
spawnpoints = (randi_range(1,5))
if spawnpoints == 1:
obstacle_spawn.global_position = $SpawnPoint1.global_position
obstacle_spawn.global_rotation = $SpawnPoint1.global_rotation
$SpawnPoint1.add_child(obstacle_spawn)
if spawnpoints == 2:
obstacle_spawn.global_position = $SpawnPoint2.global_position
obstacle_spawn.global_rotation = $SpawnPoint1.global_rotation
$SpawnPoint2.add_child(obstacle_spawn)
if spawnpoints == 3:
obstacle_spawn.global_position = $SpawnPoint3.global_position
obstacle_spawn.global_rotation = $SpawnPoint1.global_rotation
$SpawnPoint3.add_child(obstacle_spawn)
if spawnpoints == 4:
obstacle_spawn.global_position = $SpawnPoint4.global_position
obstacle_spawn.global_rotation = $SpawnPoint1.global_rotation
$SpawnPoint4.add_child(obstacle_spawn)
if spawnpoints == 5:
obstacle_spawn.global_position = $SpawnPoint5.global_position
obstacle_spawn.global_rotation = $SpawnPoint1.global_rotation
$SpawnPoint5.add_child(obstacle_spawn)
SpawnPoint(n) 是位于应生成块的边界之外的标记 2D 节点。无论如何,它们都不会生成。
我可能做错了什么
godot 4.3 中有一个寻路节点,所以你可以尝试使用它,或者你可以让对象保持静止,只让玩家移动。