Effects

Effects can be thought of as lightweight abilities. Effects allow for extra camera/item movements that are applied to the character. Examples of an effect include an earthquake shake or boss stomp. Effects do not affect the Animator and are not synchronized over the network. For anything more involved an ability should be used instead.

API

Effects can be started/stopped manually from any script by getting a reference to the Ultimate Character Locomotion component and then calling the TryStartEffect or TryStopEffect method on that component. These methods require a reference to the effect that will be started/stopped and that reference can be retrieved with GetEffect.

using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Effects;

public class MyObject : MonoBehaviour
{
    [Tooltip("The character that should start and stop the earthquake effect.")]
    [SerializeField] protected GameObject m_Character;

    /// <summary>
    /// Starts and stops the earthquake effect.
    /// </summary>
    private void Start()
    {
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        var earthquakeEffect = characterLocomotion.GetEffect<Earthquake>();
        // Tries to start the earthquake effect. There are many cases where the effect will not start, 
        // such as if it isn't enabled or if CanStartEffect returns false.
        characterLocomotion.TryStartEffect(earthquakeEffect );

        // Stop the effect if it is active.
        if (earthquakeEffect.IsActive) {
            characterLocomotion.TryStopEffect(earthquakeEffect);
        }
    }
}

New Effect

Effects can be created relatively easily by overriding a couple of methods. The basic flow for the effect life cycle is:

EffectStarted

The controller has started the effect.

Update

The effect is active and the controller calls the Update method to update the effect.

EffectStopped

The controller has stopped the effect.

Example

The following effect will shake the camera for 3 seconds, after which the StopEffect method is called to stop the effect. This example uses the Scheduler to stop the effect after the event has elapsed.

using Opsive.UltimateCharacterController.Character.Effects;
using Opsive.UltimateCharacterController.Game;
using Opsive.UltimateCharacterController.Motion;

public class MyEffect : Effect
{
    protected override void EffectStarted()
    {
        base.EffectStarted();

        Scheduler.Schedule(3, StopEffect);
    }

    public override void Update()
    {
        m_CameraController.AddPositionalForce(SmoothRandom.GetVector3Centered(1));
        m_CameraController.AddRotationalForce(SmoothRandom.GetVector3Centered(1));
    }
}