   moved: false
   sprinted: false
 
+  intersects: []
+
+  directions: {
+    axe: new THREE.Vector3(0, 1, 0)
+    default: new THREE.Vector3(0, 0, 1)
+    down: new THREE.Vector3(0, -1, 0)
+  }
+
   constructor: (camera, @defaultPosition, @objects) ->
     @cameraPitch = camera
     @cameraYaw = camera

  getCamera: ->
    @cameraYaw

  getIntersect: (direction) ->
    @rayCaster.set(new THREE.Vector3(@cameraYaw.position.x, @cameraYaw.position.y-5, @cameraYaw.position.z), direction)
    @rayCaster.far = if @sprinted then @speed * 2 else @speed
    intersections = @rayCaster.intersectObjects(@objects)
    console.log(@cameraYaw.position.y-11)
    return true if intersections.length > 0

  update: (delta, pointerLocked) ->
    # Gravity
    @velocity.y -= 9.823 * 3.0 * delta


    speed = if @sprinted then @speed * 2 else @speed

    # Intersects
    distance = @getIntersect(@directions.down).distance
    @height = Math.abs(Math.round(@position.y - distance)) + @defaultPosition.y

    angle = Math.PI / 4
    direction = @directions.default.clone().applyAxisAngle(@directions.axe, @rotation.y)
    @intersects[0] = !!@getIntersect(direction, speed)

    for idx in [1..7]
      direction = direction.applyAxisAngle(@directions.axe, angle)
      @intersects[idx] = !!@getIntersect(direction, speed)

    intersectBack = @intersects[7] or @intersects[0] or @intersects[1]
    intersectRight = @intersects[1] or @intersects[2] or @intersects[3]
    intersectFront = @intersects[3] or @intersects[4] or @intersects[5]
    intersectLeft =  @intersects[5] or @intersects[6] or @intersects[7]

    if @moved and pointerLocked
      @velocity.z -= speed * delta if keyW and not intersectFront
      @velocity.z += speed * delta if keyS and not intersectBack
      @velocity.x -= speed * delta if keyA and not intersectLeft
      @velocity.x += speed * delta if keyD and not intersectRight

    # Jumping
    if Key.isPressed("space")
