Exemple #1
0
    //Happens every frame in Edit mode.
    //Uses transform.position of the enemy to approximate what they would do in Play mode with the NavMeshAgent
    private void ProcessEditModeFrame(Playable playable)
    {
        previousInputFinalPosition = defaultPosition;
        int inputCount = playable.GetInputCount();

        for (int i = 0; i < inputCount; i++)
        {
            float inputWeight = playable.GetInputWeight(i);

            ScriptPlayable <EnemyControlBehaviour> inputPlayable;
            inputPlayable = (ScriptPlayable <EnemyControlBehaviour>)playable.GetInput(i);
            EnemyControlBehaviour input = inputPlayable.GetBehaviour();

            //final position je to isté ako targetposition
            finalPosition = input.targetPosition;

            if (inputWeight > 0f)
            {
                double progress = inputPlayable.GetTime() / inputPlayable.GetDuration();
                newPosition = Vector3.Lerp(previousInputFinalPosition, finalPosition, (float)progress);
                enemy.transform.position = newPosition;
                continue;
            }
            else
            {
                previousInputFinalPosition = finalPosition;                 //cached to act as initial position for the next input
            }
        }
    }
Exemple #2
0
    //Happens in Play mode
    //Uses the NavMeshAgent to control the units, delegating their movement and animations to the AI
    private void ProcessPlayModeFrame(Playable playable)
    {
        int inputCount = playable.GetInputCount();

        for (int i = 0; i < inputCount; i++)
        {
            float inputWeight = playable.GetInputWeight(i);
            if (inputWeight > 0f)
            {
                ScriptPlayable <EnemyControlBehaviour> inputPlayable;
                inputPlayable = (ScriptPlayable <EnemyControlBehaviour>)playable.GetInput(i);
                EnemyControlBehaviour input = inputPlayable.GetBehaviour();

                NavMeshAgent agent = enemy.GetComponent <NavMeshAgent>();
                agent.SetDestination(input.targetPosition);
            }
        }
    }