Skip to content Skip to sidebar Skip to footer

Continuously Moving Aframe Camera Into Direction Of View

I want to continuously move the view of my Aframe scene in the current viewing direction. There seem to be two components to do this, (1) getting current viewing direction in corre

Solution 1:

I think the direction of view should be in THREE.Vector3() type, you can get the direction like this:

var camera = document.querySelector("a-camera");
var direction = new THREE.Vector3().copy(camera.getWorldDirection());

Cause tick function would be executed in every render loop, if you use the component tick function to implement the movement, you may don't need an animation, just let the camera take a little step in the view direction. The code is like:

tick : fucntion()
{
    var camera = document.querySelector("a-camera");
    var stepFactor = 0.1;
    camera.parent.position.add(this.direction.multiplyScalar(stepFactor));
}

<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/aframe/0.5.0/aframe.min.js"></script><scriptsrc="//cdn.rawgit.com/donmccurdy/aframe-extras/v3.7.0/dist/aframe-extras.min.js"></script><!DOCTYPE html><html><head><title>Camera Movement</title></head><body><scripttype="text/javascript">AFRAME.registerComponent("listener", {
		schema : 
		{
			stepFactor : {
				type : "number",
				default : 0.05
			}
		},
		tick : function()
		{	this.el.components.camera.camera.parent.position.add(this.el.components.camera.camera.getWorldDirection().multiplyScalar(this.data.stepFactor));
		}
	});
</script><a-scene><a-cameralistener="stepFactor:0.01"position="0 0 30"><a-entityid="cursor"cursor="fuse: true;fuseTimeout:500"material="color:black"geometry="primitive:ring"position="0 0 -1"scale="0.01 0.01 0.01"
    ></a-entity></a-camera><a-grid></a-grid><a-boxposition="0 1 -2"color="blue"moveeve></a-box></body></html>

I attached the component to the a-camera entity, so, this.el equals a-camera DOM element.

Post a Comment for "Continuously Moving Aframe Camera Into Direction Of View"