一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

godot-rapier-physics:实践指南

时间:2026-09-11 10:38:01 编辑:袖梨 来源:一聚教程网

实际看godot-rapier-physics,先要确认它的用途:Godot RapierPhysics – Godot 游戏引擎的 2D 和 3D 物理引擎,具有更好的稳定性、性能、液体、确定性、状态序列化和无幽灵碰撞。日常自动化里,输入边界、依赖和失败处理如果不清楚就很难稳定复用。我会用一项范围明确的真实任务完成最小试跑,检查配置时间、输出质量、异常信息和维护痕迹。它适合愿意先做小范围验证并复查原始文档的团队;采用前仍要看维护状态和试跑结果。

appsinacup/godot-rapier-physics 项目截图 1

适用于适用于:桌面、移动和 Web

2D 和 3D 物理 engine for 戈多游戏 engine. 与更好的stability,performance,liquids,determinism,state serialization和no幽灵collisions。

Godot RapierPhysics 是 Godot 游戏引擎 到 剑杆 物理引擎 salva 流体模拟库的 2D 和 3D 物理直接替代品。

特点

稳定性 无振动
二维流体 流体 3D
身体皮肤 逆运动学
无幽灵碰撞 改进的堆叠
序列化 反序列化
保存物理状态 负载物理状态
局部确定性 跨平台确定性
每次都精确模拟(在同一平台上) 多平台精确模拟

安装

  • 自动(推荐):使用 Godot 中的 Asset Store 选项卡从官方 Godot Asset Store 下载插件:

    • 剑杆物理 2D
    • 剑杆物理 3D

    Note: There is a single build per dimension. It runs the parallel SIMD solver and is cross platform deterministic.

  • 手册:下载 最新的 github 版本 并仅将 addons 文件夹移动到项目 addons 文件夹中。

安装完成后,进入Advanced Settings -> Physics -> 2D3D。将 Physics Engine 更改为 Rapier2DRapier3D

Rust 依赖

请参见 godot-rust/ExtensionLibrary。

[dependencies]
godot-rapier = { git = "https://github.com/appsinacup/godot-rapier-physics.git", tag = "v0.35.2", features = ["single-dim2"] }

与已发布的插件版本相匹配的功能集:

构建 特点
二维 single-dim2, serde-serialize, parallel, experimental-threads, register-docs, api-4-7
3D single-dim3, serde-serialize, parallel, experimental-threads, register-docs, api-4-7

仅使用一个 Godot API 特征:api-4-4api-4-5api-4-6api-4-7

SIMD 和跨平台确定性不是您选择的功能:SIMD 始终被编译(在缺少它的目标上进行标量回退),并且在每个构建的 Rapier 依赖项上启用 enhanced-determinismparallel 保持可选,因为 Web 构建无法使用它。

对于 web/Emscripten 构建,添加一项 Web 功能:experimental-wasm(用于线程 Web 构建)或 experimental-wasm-nothreads(用于无线程 Web 构建)。 experimental-wasm-nothreads 包括 experimental-wasm。 CI 使用 wasm32-unknown-emscriptenrelease-wasm-Zbuild-std 构建 Web。

当依赖另一个 GDExtension 箱时,将 GDRUST_MAIN_EXTENSION 设置为您的扩展的 ExtensionLibrary 类型,并从您的扩展显式转发 Godot Rapier 的初始化阶段。 Godot 仅运行一个主 ExtensionLibrary,因此用户的扩展也必须注册 Rapier 服务器和类:

use godot::prelude::*;
use godot_rapier::RapierPhysics3DExtensionLibrary;

struct MyExtension;

#[gdextension]
unsafe impl ExtensionLibrary for MyExtension {
    fn min_level() -> InitLevel {
        InitLevel::Servers
    }

    fn on_stage_init(level: InitStage) {
        RapierPhysics3DExtensionLibrary::on_stage_init(level);
    }

    fn on_stage_deinit(level: InitStage) {
        RapierPhysics3DExtensionLibrary::on_stage_deinit(level);
    }
}

对于 2D 项目,请使用 RapierPhysics2DExtensionLibrary

通过另一个 Rust GDExtension 捆绑时,不要在同一个 Godot 项目中加载独立的 Godot Rapier 插件,因为 Godot 类可以注册两次。

展示柜

您有使用此插件构建的游戏或应用程序吗?我们在 godot.rapier.rs/showcase 上展示它们。在此提交您的参赛作品 here。

实施进度

2D部分相当稳定,虽然存在一些问题,但3D部分仍然缺少一些东西。请参阅 实施进度 以了解它的状态以及它具有哪些功能。

局限性

  • 双重构建需要手动构建。
  • 不支持非对称碰撞(例如,对象 1 撞击对象 2,但对象 2 未撞击对象 1)。这是剑杆所做的精确检查:(A.layer & B.mask) != 0 || (B.layer & A.mask) != 0

模块构建

要将其构建为模块,请转到:

  • Godot剑杆物理模块 2D
  • Godot剑杆物理模块 3D

热门栏目