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

Commit

Permalink
LerpTransform from rigid body uses rigid body instead of scene entity (
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBelmes authored Aug 6, 2024
1 parent 1b3f726 commit 609b136
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { ECSState } from '@etherealengine/ecs/src/ECSState'
import { getState } from '@etherealengine/hyperflux'

import { Vector3_One, Vector3_Zero } from '../../common/constants/MathConstants'
import { SceneComponent } from '../../renderer/components/SceneComponents'
import { EntityTreeComponent, getAncestorWithComponent, iterateEntityNode } from '../../transform/components/EntityTree'
import { TransformComponent } from '../../transform/components/TransformComponent'
import { computeTransformMatrix, isDirty, TransformDirtyUpdateSystem } from '../../transform/systems/TransformSystem'
Expand Down Expand Up @@ -79,13 +78,13 @@ export const lerpTransformFromRigidbody = (entity: Entity, alpha: number) => {

const transform = getComponent(entity, TransformComponent)

const sceneEntity = getAncestorWithComponent(entity, SceneComponent)
const sceneTransform = getComponent(sceneEntity, TransformComponent)
parentMatrixInverse.copy(sceneTransform.matrixWorld).invert()
const rigidBodyEntity = getAncestorWithComponent(entity, RigidBodyComponent)
const rigidBodyTransform = getComponent(rigidBodyEntity, TransformComponent)
parentMatrixInverse.copy(rigidBodyTransform.matrixWorld).invert()
localMatrix.compose(position, rotation, Vector3_One).premultiply(parentMatrixInverse)
localMatrix.decompose(position, rotation, scale)
transform.matrix.compose(position, rotation, transform.scale)
transform.matrixWorld.multiplyMatrices(sceneTransform.matrixWorld, transform.matrix)
transform.matrixWorld.multiplyMatrices(rigidBodyTransform.matrixWorld, transform.matrix)

/** set all children dirty deeply, but set this entity to clean */
iterateEntityNode(entity, setDirty)
Expand Down

0 comments on commit 609b136

Please sign in to comment.