MD3 - improve animations support

Indeed TCastleThirdPersonNavigation expected to control animations using TCastleScene.AutoAnimation. So it assumed that the animation is played by TCastleScene.

I thought about possible answers, even pondering a recommendation to fork our CastleThirdPersonNavigation unit into your own.

… But then I realized I can easily make the TCastleThirdPersonNavigation class more flexible. I made the SetAnimation method virtual – see this GitHub commit which includes documentation how SetAnimation should behave: Make SetAnimation virtual, allow to override it in descendants · castle-engine/castle-engine@88dc2b9 · GitHub . As usual, I pushed the change to GitHub and it will take a while but eventually it will be available in the downloads on Download | Castle Game Engine . Watch this page: Comparing snapshot...master · castle-engine/castle-engine · GitHub , when it will no longer show the commit " Make SetAnimation virtual, allow to override it in descendants" → it means that this commit is now part of download on Download | Castle Game Engine .

The way to use it:

Define your own descendant of TCastleThirdPersonNavigation in your game that overrides SetAnimation. Like this:

type
  TMyThirdPersonNavigation = class(TCastleThirdPersonNavigation)
  protected
    procedure SetAnimation(const AnimationNames: array of String); override;
  end;

procedure TMyThirdPersonNavigation.SetAnimation(const AnimationNames: array of String);
begin
  // Apply desired animation in any way.
  // You are most interested in AnimationNames[0].
  // Over-simplifying, you can think that default implementation does "Avatar.AutoAnimation := AnimationNames[0]"
end;

Next use this class. You can add it to the viewport from code e.g. in view start:

procedure TMyView.Start;
var
  MyNavigation: TMyThirdPersonNavigation;
begin
  inherited;
  MyNavigation := TMyThirdPersonNavigation.Create(FreeAtStop);
  // adjust any parameters you need:MyNavigation.CameraSpeed := 9;
  MyViewport.InsertBack(MyNavigation);
end;

Make sure to remove the previous navigation, if you added any (by code or in editor).

Alternatively, you could register your custom navigation class following Custom Components | Manual | Castle Game Engine . This way TMyThirdPersonNavigation will be available at design-time, in the editor. Ignore this if this sounds too complicated :slight_smile:

Note: We are designing with Andrzej Kilijański a new approach to more modular “navigation classes”. They will be simpler, split into behaviors, and will make it easier to “roll your own navigation”. Initially a big simplification for 1st-person navigation, they will also come to offer simpler alternative to 3rd-person navigation. Watch CGE news in the upcoming weeks :slight_smile: