Third person navigation to navigate a car

Hi there,

i use the third person navigation to navigate a car in my racing game.
my car is the avatar.

following works fine:
ThirdPersonNavigation.Input_LeftRotate.Assign(keyArrowLeft);
ThirdPersonNavigation.Input_RightRotate.Assign(keyArrowRight);

but i use one button for moving forward:
ThirdPersonNavigation.Input_Forward.Assign(keyR);

with arrowup and arrowdown i increase or decrease ThirdPersonNavigation.MoveSpeed.
when i stop pushing up (down is to break), the car is moving forward with very slow deceleration, like a car in real world would do.
my problem is, that i have to hold the keyR down all the time. after 10 rounds my finger hurts!

maybe someone has an idea how this could be improved.

thanks in advance
Didi

I think in this case you can move the car directly, following any logic you like, without depending on built-in input shortcuts Input_Xxx in TCastleThirdPersonNavigation.

That is, inside the Update method of your state, just check for something and move the car directly, like

procedure TStateMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
const
  CarSpeed = 5.0; // units per second
begin
  inherited;
  if CarMoving then
    Car.Move(Car.Direction * SecondsPassed * CarSpeed);
end;

function TStateMain.Press(const Event: TInputPressRelease): Boolean;
begin
  Result := inherited;
  if Result then Exit; // allow the ancestor to handle keys
 
  if Event.IsKey(keySomethingToStart) then
  begin
    CarMoving := true;
    Exit(true); // event was handled
  end;

  if Event.IsKey(keySomethingToStop) then
  begin
    CarMoving := false;
    Exit(true); // event was handled
  end;
end;

where Car is the TCastleTransform , the same thing you use as AvatarHierarchy or Avatar in TCastleThirdPersonNavigation.

(see Designing user interface and handling events (press, update) within the state | Manual | Castle Game Engine about state methods Update and Press).

Internallly, TCastleThirdPersonNavigation.Update does mostly the same. It calculates A as

function TCastleThirdPersonNavigation.RealAvatarHierarchy: TCastleTransform;
begin
  if AvatarHierarchy <> nil then
    Result := AvatarHierarchy
  else
    Result := Avatar;
end;

and then does

...
    if Input_Forward.IsPressed(Container) then
    begin
      Moving := true;
      T := T + A.Direction * Speed * SecondsPassed;
    end;
...
    if not T.IsPerfectlyZero then
      A.Move(T, false);
...

thank you very much, the navigation works now how it should.