Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Add setRigidBodyType (#7286)
Browse files Browse the repository at this point in the history
* Add setRigidBodyType

* make setRigidBodyType actually set rigidbody type

Co-authored-by: HexaField <joshfield999@gmail.com>
  • Loading branch information
speigg and HexaField authored Nov 29, 2022
1 parent f070d82 commit 6ed8d76
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/engine/src/physics/components/RigidBodyComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { Quaternion, Vector3 } from 'three'

import { proxifyQuaternion, proxifyVector3 } from '../../common/proxies/createThreejsProxy'
import { Engine } from '../../ecs/classes/Engine'
import { createMappedComponent, defineComponent, removeComponent } from '../../ecs/functions/ComponentFunctions'
import { Entity } from '../../ecs/classes/Entity'
import {
createMappedComponent,
defineComponent,
getComponent,
removeComponent,
setComponent
} from '../../ecs/functions/ComponentFunctions'

const { f64 } = Types
const Vector3Schema = { x: f64, y: f64, z: f64 }
Expand Down Expand Up @@ -84,3 +91,12 @@ export const getTagComponentForRigidBody = (type: RigidBodyType): RigidBodyTypes
return RigidBodyKinematicVelocityBasedTagComponent
}
}

export const setRigidBodyType = (entity: Entity, type: RigidBodyType) => {
const rigidbody = getComponent(entity, RigidBodyComponent)
const oldTypeTag = getTagComponentForRigidBody(rigidbody.body.bodyType())
removeComponent(entity, oldTypeTag)
rigidbody.body.setBodyType(type)
const typeTag = getTagComponentForRigidBody(type)
setComponent(entity, typeTag)
}

0 comments on commit 6ed8d76

Please sign in to comment.