Code Monkey home page Code Monkey logo

Comments (4)

skompc avatar skompc commented on July 20, 2024

I had this problem at first... Use this to go forward:
+ VR.camera.moveZ(-(Math.PI * delta * 2));

And this to go backwards (away from where ur looking at):
+ VR.camera.moveZ(-(Math.PI * delta * 2));

from webvr-starter-kit.

skompc avatar skompc commented on July 20, 2024

Ignore the pluses

from webvr-starter-kit.

skompc avatar skompc commented on July 20, 2024

Darn!... This to go back: VR.camera.moveZ(Math.PI * delta * 2);

from webvr-starter-kit.

brianchirls avatar brianchirls commented on July 20, 2024

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);
  }
});

live example

from webvr-starter-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.