コード例 #1
0
  public SlidingThrottleController(
      MovableAcobject s,
      SteeringControls controls,
      float minSpeed,
      float midSpeed,
      float maxSpeed,
      FloatSpring accelerationSpring,
      float velocityHalflife) {
    super();
    this.s = s;
    this.controls = controls;
    this.midSpeed = midSpeed;
    this.maxSpeed = maxSpeed;
    this.minSpeed = minSpeed;
    this.accelerationSpring = accelerationSpring;

    // Initialise speed spring to desired velocity, no spring velocity (spatial acceleration)
    accelerationSpring.setVelocity(0);
    accelerationSpring.setPosition(desiredSpeedForThrottle());

    // Make velocity decay
    velocityDecay = new FloatDecay3f(velocityHalflife);

    // Current speed is desired speed
    currentSpeed = desiredSpeedForThrottle();
  }
コード例 #2
0
  @Override
  public void update(float time) {

    // Update for current speed
    accelerationSpring.update(desiredSpeedForThrottle(), time);
    currentSpeed = accelerationSpring.getPosition();

    // s.moveLocal(2, currentSpeed * time);

    // Work out desired velocity, as target for decay
    NodeTranslator.makeTranslationVector(
        s.getRotation(), 2, currentSpeed, velocityDecay.getTarget());

    // Decay velocity towards desired
    velocityDecay.update(time);

    // Make the move
    move.set(velocityDecay.getPosition());
    move.multLocal(time);
    s.moveGlobal(move);
  }