Created
December 28, 2019 12:42
-
-
Save BlueMagnificent/de75266af1b5973093234a230946ca88 to your computer and use it in GitHub Desktop.
Javascript 3D Physics Tut 2 Move Kinematic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function moveKinematic(){ | |
let scalingFactor = 0.3; | |
let moveX = kMoveDirection.right - kMoveDirection.left; | |
let moveZ = kMoveDirection.back - kMoveDirection.forward; | |
let moveY = 0; | |
let translateFactor = tmpPos.set(moveX, moveY, moveZ); | |
translateFactor.multiplyScalar(scalingFactor); | |
kObject.translateX(translateFactor.x); | |
kObject.translateY(translateFactor.y); | |
kObject.translateZ(translateFactor.z); | |
kObject.getWorldPosition(tmpPos); | |
kObject.getWorldQuaternion(tmpQuat); | |
let physicsBody = kObject.userData.physicsBody; | |
let ms = physicsBody.getMotionState(); | |
if ( ms ) { | |
ammoTmpPos.setValue(tmpPos.x, tmpPos.y, tmpPos.z); | |
ammoTmpQuat.setValue( tmpQuat.x, tmpQuat.y, tmpQuat.z, tmpQuat.w); | |
tmpTrans.setIdentity(); | |
tmpTrans.setOrigin( ammoTmpPos ); | |
tmpTrans.setRotation( ammoTmpQuat ); | |
ms.setWorldTransform(tmpTrans); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment