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
相关推荐
魔士于安4 小时前
unity 音乐会场景 unity2022
游戏·unity·游戏引擎·贴图·模型
一线灵6 小时前
Axmol 3.x 输入系统重构:从 Touch/Mouse 到统一 Pointer,再到现代 InputField
重构·游戏引擎
Zwarwolf6 小时前
Godot零散知识点项目汇总
游戏引擎·godot
游乐码9 小时前
Unity基础(十四)场景异步加载
unity·游戏引擎
mxwin10 小时前
Unity Shader URP:法线在空间变换上的特殊性
unity·游戏引擎·shader
charlee4411 小时前
Unity在安卓端如何调试输出信息
android·unity·adb·游戏引擎·真机调试
TCW112112 小时前
Minetest游戏引擎源代码解析
游戏引擎
一锅炖出任易仙1 天前
创梦汤锅学习日记day32
学习·ai·游戏引擎
mxwin1 天前
Unity URP 法线贴图如何生成 用什么工具创建
unity·游戏引擎·贴图
mxwin2 天前
Unity URP 法线贴图色彩空间、编码与解码
unity·游戏引擎·贴图·shader