Adventure Creator Wikia
Advertisement

While using Unity's Timeline, a 3D character's position and rotation can be updated if they are included as an Animation track. However, when control is resumed to AC, the character's rotation will - by default - return to their original direction. Attaching the following script to the character will prevent this:

UpdateCharTimelineRotation.cs:

using UnityEngine;
using UnityEngine.Playables;

namespace AC
{

	public class UpdateCharTimelineRotation : MonoBehaviour
	{

		#region Variables

		private PlayableDirector activeDirector;
		private Char character;
		
		#endregion


		#region UnityStandards

		private void OnEnable ()
		{
			character = GetComponent <Char>();

			EventManager.OnCharacterEnterTimeline += OnCharacterEnterTimeline;
			EventManager.OnCharacterExitTimeline += OnCharacterExitTimeline;
		}


		private void OnDisable ()
		{
			EventManager.OnCharacterEnterTimeline -= OnCharacterEnterTimeline;
			EventManager.OnCharacterExitTimeline -= OnCharacterExitTimeline;
		}


		private void Update ()
		{
			if (activeDirector != null)
			{
				character.SetRotation (character.GetAnimator ().rootRotation);
			}
		}

		#endregion


		#region CustomEvents

		private void OnCharacterEnterTimeline (Char character, PlayableDirector director, int trackIndex)
		{
			activeDirector = director;
		}


		private void OnCharacterExitTimeline(Char character, PlayableDirector director, int trackIndex)
		{
			if (activeDirector == director)
			{
				activeDirector = null;
			}
		}

		#endregion

	}

}
Advertisement