# MD3 - improve animations support

**URL:** https://forum.castle-engine.io/t/md3-improve-animations-support/775
**Category:** 3D
**Created:** [March 23, 2023, 7:32pm UTC](https://forum.castle-engine.io/t/md3-improve-animations-support/775 "2023-03-23T19:32:40Z")
**Posts on this page:** 1
**Showing post:** 71

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [May 22, 2023, 11:36pm UTC](https://forum.castle-engine.io/t/md3-improve-animations-support/775/71 "2023-05-22T23:36:09Z")

</div>

> [@JPF12141999](#):
>
> It appears that when I try to add a “ThirdPersonNavigation” Navigation object, it only lets you use nonsegmented/one piece models as avatars, and won’t let you use castle transforms that contain multiple parts, like the example uses.
> 
> Do you know of a good workaround, to make a third person camera that lets you use multi-part models as well as single part models for reference avatars that the camera should follow all the time?

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](https://github.com/castle-engine/castle-engine/commit/88dc2b9e172a250a651eca029972307fac086869) . 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](https://castle-engine.io/download) . Watch this page: [Comparing snapshot...master · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/compare/snapshot...master) , 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](https://castle-engine.io/download) .

The way to use it:

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

```delphi
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:

```auto
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](https://castle-engine.io/custom_components) . This way `TMyThirdPersonNavigation` will be available at design-time, in the editor. Ignore this if this sounds too complicated 🙂

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 🙂

---

_[View the full topic](https://forum.castle-engine.io/t/md3-improve-animations-support/775)._
