# 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="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FWUe3OKh0gxQBlW1lB8FR%2FScreenshot_12.png?alt=media&#x26;token=736ad40b-14b7-4e78-aaa0-5fd8cd441b6f" alt=""><figcaption></figcaption></figure>
