This has to do with Three.js + Socket IO + CANNON.js. I have an CANNON.RigidBody object on my SERVER, that i cannot send as it is. So i transform it like this:
// Create a sphere
var mass = 5,
radius = 1.8;
var sphereShape = new CANNON.Sphere(radius);
var physicsMaterial = new CANNON.Material("slipperyMaterial");
var sphereBody = new CANNON.RigidBody(mass, sphereShape, physicsMaterial);
sphereBody.position.set(0, 10, 0);
sphereBody.linearDamping = 0.9;
cannonWorld.add(sphereBody);
cannonEntities[(numBodies++).toString()] = sphereBody;
player = {
type: "player",
data: {
id:((numBodies++).toString()),
position: sphereBody.position,
quaternion: sphereBody.quaternion,
velocity: sphereBody.velocity,
radius:radius,
mass:mass
} }
and sent it to my CLIENT....
broadcastJsonEvent(JSON.stringify(player))
In my CLIENT i pass this "player" object into my control, Normally instead of player one would pass the CANNON.RigidBody object.
controls = new PointerLockControls(camera, player);
scene.add(controls.getObject());
Because i cannot send the full object which is.... a CANNON.RigidBody i send it as that player object, and in PointerLockControls the last line looks like this... And this is where all fails.
cannonBody.position.copy(yawObject.position);
Now my player object does not have the copy method. What can i do? Please help. This is what i tried. Remember cannonBody = player!! And even if i get the copy method it still does not work.
var copyBody = new CANNON.Vec3(cannonBody.position.x,cannonBody.position.y,cannonBody.position.z);
cannonBody = $.extend(cannonBody,new CANNON.RigidBody(cannonBody.mass,new CANNON.Sphere(1.8),new CANNON.Material("slipperyMaterial")));
cannonBody.position = $.extend(copyBody);
cannonBody.position.copy(yawObject.position);
And even if i get the copy method it still does not work. :(