using UnityEngine;
using System.Collections;
using CreativeSpore.SmartColliders;
public class FollowController : MonoBehaviour
{
public enum eUpdateMode
{
/// <summary>
/// Use this if you are updating Target position during Update call
/// </summary>
LateUpdate,
/// <summary>
/// Use this if you are updating Target position during FixedUpdate call
/// </summary>
FixedUpdate
}
public Transform Target;
public float DampTime = 0.15f;
public bool ApplyTargetRotation = false;
public float RotationDampTime = 0.25f;
public eUpdateMode UpdateMode = eUpdateMode.LateUpdate;
PlayerHandle MyMax = new PlayerHandle();
private Vector3 velocity = Vector3.zero;
void Start()
{
if (Target)
{
transform.position = new Vector3(Target.position.x, Target.position.y, transform.position.z);
}
}
void LateUpdate()
{
if (UpdateMode == eUpdateMode.LateUpdate)
UpdatePosition();
}
void FixedUpdate()
{
if (UpdateMode == eUpdateMode.FixedUpdate)
UpdatePosition();
}
//NOTE: this has to be always different to the event where the player position is Updated. So if this is LateUpdate, player position should be always changed in Update
void UpdatePosition()
{
if (Target)
{
Vector3 destination = Target.position; destination.z = transform.position.z;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, DampTime);
if( ApplyTargetRotation )
{
transform.rotation = Quaternion.Lerp(transform.rotation, Target.localRotation, RotationDampTime);
}
else
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, RotationDampTime);
}
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
if(this.Target == null)
{
GameObject player = ORK.Game.GetPlayer();
if(player != null)
{
this.Target = player.transform;
}
}
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
NullReferenceException: Object reference not set to an instance of an object
ORKFramework.ButtonPlayerControlSettings.AddPlayerControl (UnityEngine.GameObject player)
ORKFramework.PlayerControlSettings.AddPlayerControl (UnityEngine.GameObject player)
ORKFramework.GameControlsSettings.AddPlayerComponents (UnityEngine.GameObject gameObject)
ORKFramework.ControlHandler.set_ControlledPlayer (UnityEngine.GameObject value)
ORKFramework.Combatants.CombatantObject.set_GameObject (UnityEngine.GameObject value)
ORKFramework.Combatants.CombatantObject.set_GameObject (UnityEngine.GameObject value)
ORKFramework.Combatants.CombatantObject.Spawn (Vector3 position, Boolean setRotation, Single yRotation, Boolean setScale, Vector3 scale)
ORKFramework.PlayerHandler.SpawnPlayer (Vector3 position, Boolean setRotation, Single yRotation, Boolean setScale, Vector3 scale)
ORKFramework.PlayerHandler.SpawnPlayer (Int32 spawnID)
ORKFramework.Events.Steps.SpawnPlayerStep.Execute (ORKFramework.Events.BaseEvent baseEvent)
ORKFramework.Events.GameEvent.ExecuteNextStep ()
ORKFramework.Events.GameEvent.ExecuteNextStep ()
ORKFramework.Events.BaseEvent.StartEvent ()
ORKFramework.Events.GameEvent.StartEvent (IEventStarter s, System.Object startingObject)
ORKFramework.Events.BaseEvent.CallGlobalEvent (.ORKGameEvent eventAsset, Int32 next, Boolean shareVariables, Boolean shareSelectedData, Boolean shareFoundObjects)
ORKFramework.Events.Steps.CallGlobalEventStep.Execute (ORKFramework.Events.BaseEvent baseEvent)
ORKFramework.Events.GameEvent.ExecuteNextStep ()
ORKFramework.Events.BaseEvent.StepFinished (Int32 next)
ORKFramework.Events.BaseEvent.EventEnded ()
ORKFramework.Behaviours.SceneChanger+d__27.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I ran into this issue a long time ago: since it usually takes ORK a few frames on scene load to instantiate the player, you need either need to delay the code changing the camera target, or make sure that the script execution order for the camera re-targeting is set after ORK.
---------------------------------------
Personal Twitter: https://twitter.com/AMO_Crate
I make RFI! https://twitter.com/NootboxGames