> For the complete documentation index, see [llms.txt](https://docs.twgamesdev.com/uhfps/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.twgamesdev.com/uhfps/guides/motion-controller/external-motions.md).

# External Motions

1. Create a new script that will inherit from the **ExternalMotionData** class and define the name of the motion.

```csharp
using System;

namespace UHFPS.Runtime
{
    [Serializable]
    public class TestExternalMotion : ExternalMotionData
    {
        public override string Name => "Test Motion";

        public override ExternalMotionModule GetPosition => null;

        public override ExternalMotionModule GetRotation => null;
    }
}
```

2. Create a new structure that will contain variables for position and rotation settings.

```csharp
using System;
using UnityEngine;

namespace UHFPS.Runtime
{
    [Serializable]
    public class TestExternalMotion : ExternalMotionData
    {
        [Serializable]
        public struct TestSettings
        {
            public Vector3 Force;
            public float Duration;
        }

        public TestSettings PositionSettings;
        public TestSettings RotationSettings;

        public override string Name => "Test Motion";

        public override ExternalMotionModule GetPosition => null;

        public override ExternalMotionModule GetRotation => null;
    }
}
```

3. Create a new subclass inside the base external motion class that will inherit from the **ExternalMotionModule** class.

```csharp
// ... public class TestExternalMotion : ExternalMotionData

public sealed class TestForce : ExternalMotionModule
{
    public override bool IsFinished => Time.time > endTime;

    private readonly Vector3 force;
    private readonly float endTime;

    public TestForce(TestSettings settings)
    {
        force = settings.Force;
        endTime = Time.time + settings.Duration;
    }

    public override Vector3 Evaluate()
    {
        return force;
    }
}
```

{% hint style="info" %}
The **Evaluate()** method will be called every time until **IsFinished** becomes true. The return value of the **Evaluate()** method is the force that will be applied to camera motion.
{% endhint %}

4. Assign a class that inherits from **ExternalMotionModule** to the **GetPosition** and **GetRotation** properties.

Here is the full code of the test force module:

```csharp
using System;
using UnityEngine;

namespace UHFPS.Runtime
{
    [Serializable]
    public class TestExternalMotion : ExternalMotionData
    {
        [Serializable]
        public struct TestSettings
        {
            public Vector3 Force;
            public float Duration;
        }

        public TestSettings PositionSettings;
        public TestSettings RotationSettings;

        public override string Name => "Test Motion";

        public override ExternalMotionModule GetPosition => new TestForce(PositionSettings);

        public override ExternalMotionModule GetRotation => new TestForce(RotationSettings);

        public sealed class TestForce : ExternalMotionModule
        {
            public override bool IsFinished => Time.time > endTime;

            private readonly Vector3 force;
            private readonly float endTime;

            public TestForce(TestSettings settings)
            {
                force = settings.Force;
                endTime = Time.time + settings.Duration;
            }

            public override Vector3 Evaluate()
            {
                return force;
            }
        }
    }
}
```

5. After creating a new external motion module, you will be able to add this module to the **External Motion State Data** of the **Player Item**.

<figure><img src="/files/G2RivMKfaoy4Vh4lSNei" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.twgamesdev.com/uhfps/guides/motion-controller/external-motions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
