Sunday, August 12, 2012

No Physijs Controls

‹prev | My Chain | next›

I got started yesterday with Physijs, a physics engine for Three.js, but was unable to get it all quite working.

The first of my two problems was that the ball that placed on avatar island is melting into the island:

I suspect that this is because the island is not a Physijs object. So I test that theory by making it one:
  // Island
  var island = new Physijs.PlaneMesh(
    new THREE.MeshBasicMaterial({color: 0x7CFC00})
And indeed, the ball no longer melts:

It does, however, still retain its annoying Kitty Pride-like for my avatar:

I had been making the body for the avatar a Physijs object:
  var body = new Physijs.CylinderMesh(
    new THREE.CylinderGeometry(1, 100, 100),
Perhaps that is the wrong approach. Instead, convert the avatar's frame of reference into a Physijs box:
  a_frame = new Physijs.BoxMesh(
    new THREE.CubeGeometry(250, 250, 250)
  a_frame.position.y = 125;
I find that I have to set the Y (up/down) position. Otherwise the cube starts embedded in the island and is forcibly ejected into the air. It is an interesting effect, but not at all desirable in this case.

At any rate, I find that I can now move my avatar's Physijs frame of reference with setLinearVelocity():
a_frame.setLinearVelocity({z: 0, y: 0, x: 100 })
But only if I remove the Three.js first person controls.

The combination of no Three.js controls and setLinearVelocity() allows me to play ball:

Though every now and then I fall down (bringing the camera with me):

It seems as though, if I want input controls for my avatar and physics, that I will need to write my own controls. I think I will get started on that tomorrow.

Day #476

No comments:

Post a Comment