edited December 2018 in ORK Support
Am trying to integrate smart platform collider by creative spore. The problem i have is that the camera component has field where the player transform is required. There is no provision for player transform in the set field type.

I thought about getting the player transform using scripting, but am not at coding. Can someone assist me with this. Below is the custom script.

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);
}
}
}
}
Post edited by gamingislove on
  • Try adding this code before the if (Target) lines:

    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!
  • @gamingislove i got this error messages

    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)
  • Hm, strange - the only way this'd come up is if the player was destroyed in the middle of spawning ...
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Or the camera is running the code searching for the player before he spawns!

    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.
    Tactics RPG Grid Battle System for ORK
    ---------------------------------------
    I make Rune Fencer Illyia: https://twitter.com/Nootboxgames
    Personal Twitter: https://twitter.com/AMO_Crate
  • Thanks @gamingislove and @Kirb i used coroutine to delay the code that sets the camera target until ork spawns the player
Sign In or Register to comment.