Reading Controller Velocity

To make our SpaceShooter “pedal to shoot”, we’ll use the pedal velocity, instead of position. If the pedal velocity is above a our “velToFire” value, we’ll spawn a shot.

We’ll get them in the Update() method of the PlayerController.cs script.

  void Update() {
    if (sgStub != null) {
      sgState = sgStub.Call<AndroidJavaObject>("getState");
      int lLegVel = sgState.Call<int>("getLeftLegVelocity");
      int rLegVel = sgState.Call<int>("getRightLegVelocity");
      if ((lLegVel > velToFire || rLegVel > velToFire) && Time.time > nextFire) {
        nextFire = Time.time + fireRate;
        Instantiate (shot, shotSpawn.position, shotSpawn.rotation);