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
相关推荐
魔士于安1 天前
unity 丑陋哥布林 哥布林有humannoid 动画没 带动画
unity·游戏引擎·材质·贴图·模型
淡海水2 天前
13-04-面试-源码级深度追问链
数据结构·unity·面试·c#·游戏引擎·源码·il2cpp
小小数媒成员3 天前
UGUI 性能优化(详细,全,深入)
开发语言·unity·游戏引擎
goujunwe4 天前
GEO 评估方法:如何自测你的内容,会不会被 AI 引用
搜索引擎·网络安全·游戏引擎·全文检索·中文分词
林川~014 天前
Unity 常用 API 与核心类全解:从生命周期到协程,附性能避坑清单(Unity 6 适配)
unity·游戏引擎·常用api
WiChP6 天前
【V0.1B16】从零开始的2D游戏引擎开发之路
开发语言·算法·游戏引擎
狂人开飞机7 天前
23、实战平台跳跃游戏
游戏·游戏引擎·godot
淡海水7 天前
11-02-Unity-Mono-vs-IL2CPP-两种脚本后端的数据结构行为差异
数据结构·unity·游戏引擎·il2cpp·mono
彧azz8 天前
初学Unity:编辑器
笔记·学习·unity·游戏引擎