Godot Best practices

Get Forward Vector

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

Await and Unity Style Coroutine

python 复制代码
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
相关推荐
Yasin Chen5 小时前
Unity TMP_SDF 分析(二)数据来源2
unity·游戏引擎
相信神话20216 小时前
《酒魂》游戏开发实战——从设计思想到 Godot 实现(单机完整版)
游戏引擎·godot
心疼你的一切9 小时前
【Unity-MCP完全指南:从零开始构建AI游戏开发助手】
人工智能·unity·ai·游戏引擎·aigc·mcp
前端不太难14 小时前
OpenClaw 如何运行 Claw 资源文件
c++·开源·游戏引擎
avi911114 小时前
UnReal-UE5虚幻蓝图如何修改
ue5·游戏引擎·虚幻·虚幻引擎·ue·蓝图·蓝图逻辑
张老师带你学1 天前
unity道具,健身房资源
科技·游戏·unity·游戏引擎·模型
开维游戏引擎1 天前
开维游戏引擎实例:五子棋
javascript·游戏·html·游戏引擎·ai编程
努力长头发的程序猿2 天前
在Unity当中使用GameFrameworkX框架的知识点
java·unity·游戏引擎
etp_2 天前
Unity Avater
unity·游戏引擎
JIes__2 天前
Unity(三)——DoTween/TimeLine
unity·游戏引擎