Max Glenister

Games & VR • 1 min read Plain text

27: Moving with gaze

Today’s hack is more an aside while I’m focussing on yet another Tevris rewrite.

I thought I’d play with an idea for controlling the left/right movement of the active piece based on where you’re looking.

Now, knowing where you’re looking in 3D space is both a hard thing to Google, and a hard thing to explain. So take this solution with a grain of salt:

var getpos = function (obj) {
  camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  var mat = new THREE.Matrix4().multiplyMatrices( camera.matrixWorldInverse, obj.matrixWorld );
  var pos = obj.position.clone().applyProjection(mat);
  return pos;
};
var getLooking = function () {
  var pos = getpos(board[0][Math.floor(cols/2)]);
  // MAGIC 💩
  if (pos.x - pos.z > 180) {
    return 'left';
  }
  if (pos.x - pos.z < 120) {
    return 'right';
  }
};

There’s a lot going on there, and some MAGIC, and it’s not going to scale, but it sort of works.

I’m not completely happy with this, so you may have noticed the poop emoji (💩) all over the place. I’ll definitely throw this away with the re-write I’m working on, but it’s nice to explore the idea.

Cardboctober · day 27

Try this hack

View this hack View the source

See the other submissions for day 27 on the Cardboctober website.

All Cardboctober days

Discussion

No interactions yet

Join the conversation

Reply from your own site with a Webmention (how?).

Webmentions last fetched 17 November 2026, 13:05