Is Needle extensible to use another physics engine?

For some games, the rapier physics library can be limiting. In this scenario, can we plug in another more suitable physics engine ?

Hi Enthusiast! Needle Engine supports the Rapier physics engine, which is used by default. However, it is designed with flexibility in mind. The engine exposes APIs to interact with the physics engine, and some of these APIs explicitly mention the Rapier engine. For example, there are APIs exposed for getting object velocity through Rapier (see the documentation).

Additionally, there is a configuration setting in Needle Engine to toggle the use of the Rapier engine. You have the option to turn off physics or adjust settings related to the physics engine (see the documentation). This means that while Rapier is integrated by default, Needle Engine allows room for potential customization and may permit extension to other engines with additional programming efforts.

For incorporating another physics engine, you would likely need to handle the integration manually. This would involve creating equivalent physics components and handling physics updates and interactions externally or via custom Needle Engine components.

Explore the provided APIs and configurations to assess how you might implement another engine, and consider reaching out to support channels for more detailed guidance specific to your project needs. If you have further questions or need assistance with coding, feel free to ask!

4 replies left
thread_1gKfbyD5yhouB4rwRSeb4u12
Reply to this post directly if you need further help (bottom right button)

Hi, yes technically you should be able to do that by implementing the IPhysicsEngine interface and assigning it to the context.physics.engine.

Could you share some more details in which cases Rapier is limiting you?

onInitialized((context) => {
    context.physics.engine = new CustomEngine();
});


class CustomEngine implements IPhysicsEngine {
    initialize(): Promise<boolean> {
        throw new Error("Method not implemented.");
    }
    get isInitialized(): boolean {
        throw new Error("Method not implemented.");
    }
    step(dt: number): void {
        throw new Error("Method not implemented.");
    }
    postStep() {
        throw new Error("Method not implemented.");
    }
    get isUpdating(): boolean {
        throw new Error("Method not implemented.");
    }
    clearCaches() {
        throw new Error("Method not implemented.");
    }
    enabled: boolean;
    get world() {
        throw new Error("Method not implemented.");
    }
    set gravity(vec3: Vec3) {
        throw new Error("Method not implemented.");
    }
    get gravity(): Vec3 {
        throw new Error("Method not implemented.");
    }
    getBody(obj: ICollider | IRigidbody);
    getBody(obj: ICollider | IRigidbody);
    getBody(obj: unknown): any {
        throw new Error("Method not implemented.");
    }
    getComponent(rapierObject: object): IComponent | null {
        throw new Error("Method not implemented.");
    }
    sphereOverlap(point: Vector3, radius: number): Array<SphereOverlapResult> {
        throw new Error("Method not implemented.");
    }
    addSphereCollider(collider: ICollider) {
        throw new Error("Method not implemented.");
    }
    addBoxCollider(collider: ICollider, size: Vector3) {
        throw new Error("Method not implemented.");
    }
    addCapsuleCollider(collider: ICollider, radius: number, height: number) {
        throw new Error("Method not implemented.");
    }
    addMeshCollider(collider: ICollider, mesh: Mesh, convex: boolean, scale?: Vector3 | undefined) {
        throw new Error("Method not implemented.");
    }
    updatePhysicsMaterial(collider: ICollider) {
        throw new Error("Method not implemented.");
    }
    wakeup(rb: IRigidbody) {
        throw new Error("Method not implemented.");
    }
    isSleeping(rb: IRigidbody): boolean | undefined {
        throw new Error("Method not implemented.");
    }
    updateProperties(rb: IRigidbody | ICollider) {
        throw new Error("Method not implemented.");
    }
    resetForces(rb: IRigidbody, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    resetTorques(rb: IRigidbody, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    addForce(rb: IRigidbody, vec: Vec3, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    applyImpulse(rb: IRigidbody, vec: Vec3, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    getLinearVelocity(rb: IRigidbody | ICollider): Vec3 | null {
        throw new Error("Method not implemented.");
    }
    getAngularVelocity(rb: IRigidbody): Vec3 | null {
        throw new Error("Method not implemented.");
    }
    setAngularVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    setLinearVelocity(rb: IRigidbody, vec: Vec3, wakeup: boolean) {
        throw new Error("Method not implemented.");
    }
    updateBody(comp: ICollider | IRigidbody, translation: boolean, rotation: boolean) {
        throw new Error("Method not implemented.");
    }
    removeBody(body: IComponent) {
        throw new Error("Method not implemented.");
    }
    addFixedJoint(body1: IRigidbody, body2: IRigidbody) {
        throw new Error("Method not implemented.");
    }
    addHingeJoint(body1: IRigidbody, body2: IRigidbody, anchor: Vec3, axis: Vec3) {
        throw new Error("Method not implemented.");
    }
    debugRenderColliders: boolean;
    debugRenderRaycasts: boolean;
    
}

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.