Mr Speaker

Three.js: looking away from .lookAt

Have a hankering to look in the opposite direction of the vector you get from Three.js's .lookAt function? You need .lookAwayFrom! Dunno if there's an easier way, but the idea is find the vector between the target you'd normally "look at" and you, then add the resultant to your current position, and look at that instead! Here's the standalone function:

function lookAwayFrom(me, target) {
    var v = new THREE.Vector3();
    v.subVectors(me.position, target.position).add(me.position);
    me.lookAt(v);
}

To face away from an enemy, you might do something like lookAwayFrom(player, enemy) and away you scarper. If you want to integrate it into Three.js, so you can do player.lookAwayFrom(enemy) then here ya go:

lookAwayFrom: function(target) {
	var v = new THREE.Vector3();
	v.subVectors(this.position, target.position).add(this.position);
	this.lookAt(v);
}
Captcha! Please type 'radical' here: *
How did you find this thingo? *