Space 1: Movement

Created: — modified: — tags: space3d

First step is moving the ship

Ok, first let's figure out how to move the ship. Babylon.js has nice functions to move the ship in ship coordinates, but we can't use them, since we want to employ physics engine. Luckily, it's very easy to fix, using this simple function:

  local2global=function(x,y,z){
      pilot.computeWorldMatrix();
      var m = pilot.getWorldMatrix();
      var v = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(x,y,z), m);
      v.subtractInPlace(pilot.getAbsolutePosition());
      return v;
  }

Controls in this demo: