Godot Best practices

Get Forward Vector

transform.x
# 等价手算
var rad = node.rotation
var forward = Vector2(cos(rad), sin(rad))

Await and Unity Style Coroutine

func coroutine(on_update: Callable, duration: float = 1):
	var elapse_time = 0
	while elapse_time < 1:
		elapse_time += get_process_delta_time() / duration
		on_update.call(elapse_time)
		await get_tree().process_frame # 等待下一帧

# normal call - 后续逻辑会在 while loop 执行一次后立刻执行
coroutine(func(): print("do coroutine"))
# test debug
start
do coroutine
end
do coroutine
do coroutine
...
# await call - 后续逻辑会等到 coroutine 执行完成之后才会执行
await coroutine(func(): print("do coroutine"))
# test debug
start
do coroutine
do coroutine
...
end

你可能感兴趣的:(godot,游戏引擎)