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
相关推荐
魔士于安13 小时前
Unity资源Toon City Pack 发电厂 工地 公园 地铁站口 银行 车 直升飞机 可动 URP
游戏·unity·游戏引擎·贴图·模型
SmartRadio15 小时前
NRF52833 + MPU6050 室内定位跟随无人机
游戏引擎·无人机·cocos2d
心前阳光16 小时前
Unity之运行时标准材质半透明无效果
unity·游戏引擎·材质
张老师带你学18 小时前
Unity buildin 石头围墙 树木 树墩子 卡通风格 栅栏 小桥 低多边形
科技·游戏·unity·游戏引擎·模型
呆呆敲代码的小Y1 天前
【Unity工具篇】| 使用YooAsset接入自己的游戏项目,实现完整热更新流程
游戏·unity·游戏引擎·热更新·yooasset·资源热更新
张老师带你学1 天前
Unity 低多边形 赛博朋克城市 拼装 模型 道路 建筑 buildin
科技·游戏·unity·游戏引擎·模型
ฅ^•ﻌ•^ฅ11 天前
Unity mcp并使用claude code制作游戏
游戏·unity·游戏引擎
张老师带你学1 天前
unity资源 buildin 低多边形 小镇村
科技·游戏·unity·游戏引擎·模型
RReality1 天前
【Unity UGUI】InputField 输入框全解
unity·游戏引擎
南無忘码至尊1 天前
Unity学习90天-第3天-认识触屏输入(手游基础)并完成手机点击屏幕,物体向点击位置移动
学习·unity·c#·游戏引擎·游戏开发