-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using three.js functions with camera. #15
Comments
I had this problem at first... Use this to go forward: And this to go backwards (away from where ur looking at): |
Ignore the pluses |
Darn!... This to go back: VR.camera.moveZ(Math.PI * delta * 2); |
Hey guys, First of all, never move the camera, because it will conflict with the headset. Move the body instead. And, of course, be careful about doing so because this is a great way to cause simulator sickness. Multiplying delta by 2 PI doesn't change anything except to speed up the movement by a factor of a little more than 6. This solution seems to work. See step-by-step explanation in comments. VR.floor();
var camera = VR.camera.object;
// create a single scratch vector to re-use so we don't have to allocate
// one on every frame. Garbage collection can cause barf-inducing judder.
var lookDirection = new THREE.Vector3();
VR.animate(function(delta){
// get direction camera is looking relative to the world
camera.getWorldDirection(lookDirection);
// set y to zero so we only move on the horizontal plane, not up or down
lookDirection.y = 0;
// don't move or try to normalize if length is very small,
// because it can cause a divide-by-zero error
// or otherwise create a weird/terrible experience
if (lookDirection.lengthSq() > 0.01) {
// normalize so we can get a constant speed
lookDirection.normalize();
lookDirection.multiplyScalar(delta);
// move body, not the camera
VR.body.position.add(lookDirection);
}
}); |
So I'm trying to get the camera towards where I am looking at. There is a method that easily allows me to do this, built into three.js:
This works fine when I put it in the animate function, but obviously I am going backwards. When I try to make delta negative the frames start to go strange and the whole thing breaks.
I know that the camera object isn't really meant to be manipulated but this is really strange.
The text was updated successfully, but these errors were encountered: