You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have one problem when building a multiplayer online game using three.js+ AMmo.js. The problem is as follows.
When the second player joining the game, the actual position of the model is changed to NaN duiring the clone model being introduced to add to the ammo physics scene with the correct position parameters.
Could you please tell me what is the reason for that? How can I solve this situation?
Finally, attaching the code:
websocket.onmessage = function(evt) {
let obj = JSON.parse(evt.data);
for(var o in obj){
if(o == local_name){
function createConvexHullPhysicsShape( coords ) {
const shape = new Ammo.btConvexHullShape();
for ( let i = 0, il = coords.length; i < il; i += 3 ) {
tempBtVec3_1.setValue( coords[ i ], coords[ i + 1 ], coords[ i + 2 ] );
const lastOne = ( i >= ( il - 3 ) );
shape.addPoint( tempBtVec3_1, lastOne );
}
return shape;
}
function createRigidBody( object, physicsShape, mass, pos, quat, vel, angVel ) {
if ( pos ) {
console.log("createRigidBody1",pos);
object.position.copy( pos );
console.log("createRigidBody2",object.position);
} else {
pos = object.position;
}
if ( quat ) {
object.quaternion.copy( quat );
} else {
quat = object.quaternion;
}
const transform = new Ammo.btTransform();
transform.setIdentity();
transform.setOrigin( new Ammo.btVector3( pos.x, pos.y, pos.z ) );
transform.setRotation( new Ammo.btQuaternion( quat.x, quat.y, quat.z, quat.w ) );
const motionState = new Ammo.btDefaultMotionState( transform );
const localInertia = new Ammo.btVector3( 0, 0, 0 );
physicsShape.calculateLocalInertia( mass, localInertia );
const rbInfo = new Ammo.btRigidBodyConstructionInfo( mass, motionState, physicsShape, localInertia );
const body = new Ammo.btRigidBody( rbInfo );
body.setFriction( 0.5 );
if ( vel ) {
body.setLinearVelocity( new Ammo.btVector3( vel.x, vel.y, vel.z ) );
}
if ( angVel ) {
body.setAngularVelocity( new Ammo.btVector3( angVel.x, angVel.y, angVel.z ) );
}
object.userData.physicsBody = body;
object.userData.collided = false;
scene.add( object );
if ( mass > 0 ) {
rigidBodies.push( object );
// Disable deactivation
body.setActivationState( 4 );
}
physicsWorld.addRigidBody( body );
return body;
}
The text was updated successfully, but these errors were encountered:
Hello, I have one problem when building a multiplayer online game using three.js+ AMmo.js. The problem is as follows.
When the second player joining the game, the actual position of the model is changed to NaN duiring the clone model being introduced to add to the ammo physics scene with the correct position parameters.
Could you please tell me what is the reason for that? How can I solve this situation?
Finally, attaching the code:
websocket.onmessage = function(evt) {
let obj = JSON.parse(evt.data);
for(var o in obj){
if(o == local_name){
};
function inputWorld(mesh,position,Quaternary){
const copy_geometry = new THREE.BufferGeometry();
copy_geometry.copy(mesh.geometry);
copy_geometry.scale(0.01,0.01,0.01);
console.log(position);
mesh.position.copy(position);
console.log("inputWorld",mesh.position);
const shape = createConvexHullPhysicsShape(copy_geometry.attributes.position.array);
shape.setMargin( margin );
const bt_body = createRigidBody( mesh, shape, 200, position, Quaternary );
bt_body.setDamping(0.8,1);
return bt_body;
}
function createConvexHullPhysicsShape( coords ) {
const shape = new Ammo.btConvexHullShape();
for ( let i = 0, il = coords.length; i < il; i += 3 ) {
tempBtVec3_1.setValue( coords[ i ], coords[ i + 1 ], coords[ i + 2 ] );
const lastOne = ( i >= ( il - 3 ) );
shape.addPoint( tempBtVec3_1, lastOne );
}
return shape;
}
function createRigidBody( object, physicsShape, mass, pos, quat, vel, angVel ) {
if ( pos ) {
console.log("createRigidBody1",pos);
object.position.copy( pos );
console.log("createRigidBody2",object.position);
} else {
pos = object.position;
}
if ( quat ) {
object.quaternion.copy( quat );
} else {
quat = object.quaternion;
}
const transform = new Ammo.btTransform();
transform.setIdentity();
transform.setOrigin( new Ammo.btVector3( pos.x, pos.y, pos.z ) );
transform.setRotation( new Ammo.btQuaternion( quat.x, quat.y, quat.z, quat.w ) );
const motionState = new Ammo.btDefaultMotionState( transform );
const localInertia = new Ammo.btVector3( 0, 0, 0 );
physicsShape.calculateLocalInertia( mass, localInertia );
const rbInfo = new Ammo.btRigidBodyConstructionInfo( mass, motionState, physicsShape, localInertia );
const body = new Ammo.btRigidBody( rbInfo );
body.setFriction( 0.5 );
if ( vel ) {
body.setLinearVelocity( new Ammo.btVector3( vel.x, vel.y, vel.z ) );
}
if ( angVel ) {
body.setAngularVelocity( new Ammo.btVector3( angVel.x, angVel.y, angVel.z ) );
}
object.userData.physicsBody = body;
object.userData.collided = false;
scene.add( object );
if ( mass > 0 ) {
rigidBodies.push( object );
// Disable deactivation
body.setActivationState( 4 );
}
physicsWorld.addRigidBody( body );
return body;
}
The text was updated successfully, but these errors were encountered: