Space 1: Movement

Created: 2017-04-13 — modified: 2017-04-15 — tags: Space

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:

  • WASD - move the ship
  • Arrows and QE - rotate the ship