Adventure Creator Wikia
Advertisement

This script lets the Player character be moved normally, while also being on a moving platform e.g. a lift/elevator.

To use it:

  1. Attach the Moveable component to the platform, and use the Object: Transform Action to move it
  2. Create a new C# file named TransferMoveable and copy/paste the script below
  3. Attach the new Transfer Moveable component to the platform and assign the Moveable component
  4. If you want to disable the effects (e.g. move the platform while the Player is not on it), use the Object: Call event Action to disable the component

TransferMoveable.cs:

using UnityEngine;
using AC;

[DefaultExecutionOrder (-1)]
public class TransferMoveable : MonoBehaviour
{

    public Moveable moveable;
    private Vector3 offset;
    private Vector3 updatePosition;

    void Update ()
    {
        offset = KickStarter.player.Transform.position - transform.position;
        updatePosition = KickStarter.player.Transform.position;
    }

    void LateUpdate ()
    {
        Vector3 deltaPosition = Vector3.zero;
        if (KickStarter.player.charState != CharState.Idle)
        {
            deltaPosition = KickStarter.player.Transform.position - updatePosition;
        }

        if (moveable.IsMoving ())
        {
            KickStarter.player.Transform.position = transform.position + offset + deltaPosition;
        }
    }

}
Advertisement