Skip to content

Commit

Permalink
Make sure a dynamic body is always owned
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 14, 2023
1 parent a6f81a8 commit 148c90e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/bit-systems/behavior-graph/bindings/rigid-body.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HubsWorld } from "../../../app";
import { EntityID } from "../../../bit-components";
import { BodyParams, getBodyFromRigidBody } from "../../../inflators/rigid-body";
import { EntityID, Rigidbody } from "../../../bit-components";
import { BodyParams, Type, getBodyFromRigidBody } from "../../../inflators/rigid-body";
import { takeSoftOwnership } from "../../../utils/take-soft-ownership";

// TODO: Fix the type conversion.
export function setRigidBody(world: HubsWorld, eid: number, params: Partial<BodyParams>) {
const physicsSystem = APP.scene?.systems["hubs-systems"].physicsSystem;
physicsSystem.updateRigidBody(eid, params);
if (Rigidbody.type[eid] === Type.DYNAMIC) {
takeSoftOwnership(world, eid);
}
}
export function getRigidBody(world: HubsWorld, eid: EntityID) {
return getBodyFromRigidBody(eid);
Expand Down
7 changes: 6 additions & 1 deletion src/systems/bit-physics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { defineQuery, enterQuery, entityExists, exitQuery, hasComponent, Not } f
import { Object3DTag, Rigidbody, PhysicsShape, AEntity, SceneRoot } from "../bit-components";
import { getShapeFromPhysicsShape } from "../inflators/physics-shape";
import { findAncestorWithComponent } from "../utils/bit-utils";
import { getBodyFromRigidBody } from "../inflators/rigid-body";
import { getBodyFromRigidBody, Type } from "../inflators/rigid-body";
import { HubsWorld } from "../app";
import { PhysicsSystem } from "./physics-system";
import { takeSoftOwnership } from "../utils/take-soft-ownership";

const rigidbodyQuery = defineQuery([Rigidbody, Object3DTag, Not(AEntity)]);
const rigidbodyEnteredQuery = enterQuery(rigidbodyQuery);
Expand All @@ -27,6 +28,10 @@ export const physicsCompatSystem = (world: HubsWorld, physicsSystem: PhysicsSyst
const body = getBodyFromRigidBody(eid);
const bodyId = physicsSystem.addBody(obj, body);
Rigidbody.bodyId[eid] = bodyId;

if (Rigidbody.type[eid] === Type.DYNAMIC) {
takeSoftOwnership(world, eid);
}
});

shapeEnterQuery(world).forEach(eid => {
Expand Down

0 comments on commit 148c90e

Please sign in to comment.