{"id":14963927,"url":"https://github.com/phaserjs/rapier-connector","last_synced_at":"2025-08-07T09:33:27.614Z","repository":{"id":253173279,"uuid":"840378973","full_name":"phaserjs/rapier-connector","owner":"phaserjs","description":"Easily use the Rapier physics library with Phaser 3","archived":false,"fork":false,"pushed_at":"2024-11-21T18:45:07.000Z","size":2470,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T11:11:27.646Z","etag":null,"topics":["game-development","phaser","phaser3","physics","rapier","webgl"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phaserjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-09T15:13:11.000Z","updated_at":"2024-11-21T18:45:11.000Z","dependencies_parsed_at":"2024-09-13T20:57:53.386Z","dependency_job_id":null,"html_url":"https://github.com/phaserjs/rapier-connector","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.15384615384615385","last_synced_commit":"a3253ce261ff59d59008f489bfe39abf5aa9044c"},"previous_names":["phaserjs/rapier-connector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phaserjs%2Frapier-connector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phaserjs%2Frapier-connector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phaserjs%2Frapier-connector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phaserjs%2Frapier-connector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phaserjs","download_url":"https://codeload.github.com/phaserjs/rapier-connector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237092913,"owners_count":19254306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-development","phaser","phaser3","physics","rapier","webgl"],"created_at":"2024-09-24T13:32:20.271Z","updated_at":"2025-02-04T09:31:57.544Z","avatar_url":"https://github.com/phaserjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rapier Plugin for Phaser 3\n\nThis connector plugin allows you to easily integrate the [Rapier](https://rapier.rs) physics library with [Phaser 3](https://phaser.io), making it simple to create and manage rigid bodies within a physical world in Phaser.\n\nFor a template that directly integrates Rapier and Phaser without using a plugin please see the [template-rapier repository](https://github.com/phaserjs/template-rapier).\n\n## Features\n\n- Support for different types of rigid bodies: Dynamic, Fixed, Kinematic position-based or velocity-based.\n- Phaser transformations: Optional integration to keep Phaser transformations (position and rotation) synchronized with physical bodies.\n- Support for various collider shapes: Boxes, Spheres, Capsules, Triangles, etc.\n- Debugging: Enable visual collider rendering for easier debugging.\n\n## Source Code Examples\n\nYou can find 15 different code examples of how to use the Rapier Connector in this [Rapier Phaser Sandbox](https://phaser.io/sandbox/full/GcQ31KLH)\n\n[![Example Image](https://raw.githubusercontent.com/phaserjs/rapier-connector/main/examples.png)](https://phaser.io/sandbox/full/GcQ31KLH)\n\n## Installation\n\nFirst, install the required dependencies via npm:\n\n```bash\nnpm i @phaserjs/rapier-connector\n```\n\n## Usage\n\n### Creating the Physics World\n\nTo get started, you need to create a RAPIER physics world within your Phaser scene:\n\n```js\nimport { RAPIER, createRapierPhysics } from 'rapier-connector';\n\nclass MyScene extends Phaser.Scene\n{\n    constructor()\n    {\n        super({ key: 'MyScene' });\n    }\n\n    preload()\n    {\n        // Load your assets here\n    }\n\n    async create()\n    {\n        // Initialize RAPIER\n        await RAPIER.init();\n\n        // Create the physics world with gravity\n        const gravity = new RAPIER.Vector2({ x: 0, y: 400 });\n\n        this.rapierPhysics = createRapierPhysics(gravity, this);\n\n        // Enable debugging (optional)\n        this.rapierPhysics.debugger(true);\n    }\n\n    update() {\n        // Scene update logic\n    }\n}\n```\n\n### Creating Rigid Bodies\n\nYou can add rigid bodies to any Phaser Game Object as follows:\n\n```js\nimport { RAPIER, createRapierPhysics } from 'rapier-connector';\n\nclass MyScene extends Phaser.Scene {\n\n    async create()\n    {\n        // Initialize RAPIER\n        await RAPIER.init();\n\n        // Create the physics world with gravity\n        const gravity = new RAPIER.Vector2({ x: 0, y: 400 });\n\n        this.rapierPhysics = createRapierPhysics(gravity, this);\n\n        const sprite1 = this.add.sprite(300, 300, 'ball');\n        \n        // Add rigid body with collider shapeType (shape collision are automatically created with the same size as the game object)\n        const body1 = this.rapierPhysics.addRigidBody(sprite1, {\n            rigidBodyType: RAPIER.RigidBodyType.Dynamic,  // Rigid body type [fixed | dynamic | kinematicVelocityBased | kinematicPositionBased]\n            collider: RAPIER.ShapeType.Ball,  // Collider shape type or colliderDesc\n        });\n\n        const sprite2 = this.add.sprite(400, 300, 'box');\n\n        // Add rigid body with colliderDesc\n        const body2 = this.rapierPhysics.addRigidBody(sprite2, {\n            rigidBodyType: RAPIER.RigidBodyType.Dynamic,\n            collider: RAPIER.ColliderDesc.cuboid(halfWidth, halfHeight),  // Custom collider shape\n        });\n\n        const sprite3 = this.add.sprite(500, 300, 'ball');\n\n        // Add rigid body with Phaser transformations enabled\n        const body3 = this.rapierPhysics.addRigidBody(sprite3, {\n            rigidBodyType: RAPIER.RigidBodyType.kinematicPositionBased,\n            collider: RAPIER.ShapeType.Ball,\n            phaserTransformations: true,\n        });\n    }\n}\n```\n\nAll rigid bodies are automatically synchronized with the Phaser Game Object's position and rotation.\n\nHowever, the `phaserTransformations` boolean only works if the rigid body is of type `KinematicPositionBased`. You can enable or disable Phaser transformations by setting the `phaserTransformations` parameter to true or false.\n\nThe `addRigidBody` method returns an object with the rigid body and collider associated with the Game Object. You can use this object to access the rigid body and collider properties, just as if they were created using native RAPIER methods. For more details, please refer to the official documentation: [RAPIER JavaScript User Guide on Rigid Bodies](https://rapier.rs/docs/user_guides/javascript/rigid_bodies).\n\n## Available Methods\n\nThe following methods are available via the Rapier Connector plugin:\n\n### `createRapierPhysics(gravity, scene)`  \n\nCreates and manages a RAPIER physics world in a Phaser Scene. Requires the following parameters:\n\n- `gravity`: Gravity vector (x, y).\n- `scene`: A Phaser Scene reference.\n\n### `addRigidBody(gameObject, options)`\n\nPairs a Phaser Game Object with a Rapier body and collider. Returns an object with the rigid body and collider associations. Takes the following parameters:\n\n- `gameObject`: The Phaser Game Object to which the rigid body will be added.\n- `options`: Optional configuration for the rigid body, including the body type, collider, and whether Phaser transformations are enabled. See the type declaration below for details:\n\n```ts\ntype TRapierOptions = {\n    /** The type of rigidbody (Dynamic, Fixed, KinematicPositionBased, KinematicVelocityBased) */\n    rigidBodyType?: RAPIER.RigidBodyType;\n    /**\n     * The collider shape, if you pass RAPIER.ColliderDesc.[ball | capsule | cuboid | ...] you need pass the shape size example: RAPIER.ColliderDesc.ball(1.5)\n     * - If you don't pass a collider, a cuboid will be created with the dimensions of the game object.\n     * - If you pass the type enum RAPIER.ShapeType, the size is created with the dimensions of the object.\n     * */\n    collider?: RAPIER.ColliderDesc | RAPIER.ShapeType;\n    /** If you pass some KinematicPositionBased then you can use Phaser's transformations. NOTE: Phaser transformations are only available for KinematicPositionBased rigid bodies. Scale is not supported please do it manually  */\n    phaserTransformations?: boolean;\n};\n```\n\n### `debugger(enable)`   \n\nThis function will toggle visual debugging of colliders.\n\n- `enable`: A boolean property that enables or disables visual debugging of colliders.\n\n### `destroy(gameObject)`\n\nDestroys the Game Object and its rigid body, preventing memory leaks.\n\n- `gameObject`: The Game Object that will be destroyed along with its rigid body.\n\n## Official Documentation\n\n- [RAPIER JavaScript User Guide](https://rapier.rs/docs/user_guides/javascript/getting_started_js)\n- [Phaser API Documentation](https://newdocs.phaser.io)\n\n## Additional Notes\n\nIf this library does not provide everything you need to develop with RAPIER, please consider using RAPIER natively. For a template that directly integrates Rapier and Phaser without using this plugin please see the [template-rapier repository](https://github.com/phaserjs/template-rapier).\n\nIf you make some useful additions to this library, please submit them as a pull request.\n\n## Join the Phaser Community!\n\nWe love to see what developers like you create with Phaser! It really motivates us to keep improving. So please join our community and show-off your work 😄\n\n**Visit:** The [Phaser website](https://phaser.io) and follow on [Phaser Twitter](https://twitter.com/phaser_)\u003cbr /\u003e\n**Play:** Some of the amazing games [#madewithphaser](https://twitter.com/search?q=%23madewithphaser\u0026src=typed_query\u0026f=live)\u003cbr /\u003e\n**Learn:** [API Docs](https://newdocs.phaser.io), [Support Forum](https://phaser.discourse.group/) and [StackOverflow](https://stackoverflow.com/questions/tagged/phaser-framework)\u003cbr /\u003e\n**Discord:** Join us on [Discord](https://discord.gg/phaser)\u003cbr /\u003e\n**Code:** 2000+ [Examples](https://labs.phaser.io)\u003cbr /\u003e\n**Read:** The [Phaser World](https://phaser.io/community/newsletter) Newsletter\u003cbr /\u003e\n\nCreated by [Phaser Studio](mailto:support@phaser.io). Powered by coffee, anime, pixels and love.\n\nThe Phaser logo and characters are \u0026copy; 2011 - 2024 Phaser Studio Inc.\n\nAll rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphaserjs%2Frapier-connector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphaserjs%2Frapier-connector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphaserjs%2Frapier-connector/lists"}