Example #1
0
    public override void Update()
    {
        /*if (Owner.IsPlayer)
         * {
         * //   Debug.Log(AnimNameBase + " " + Animation[AnimNameBase].weight);
         *
         * string s = "Anims:";
         * foreach (AnimationState state in Owner.animation)
         * {
         * if (Owner.animation.IsPlaying(state.clip.name) == false)
         *  continue;
         *
         * s += " " + state.clip.name + " " + state.weight.ToString();
         *
         * }
         *
         * Debug.Log(s);
         * }*/

//        Debug.Log(Owner.Transform.forward);
        if (PositionOK == false)
        {
            //Debug.DrawLine(StartPosition, FinalPosition, Color.blue, 2);
            CurrentMoveTime += Time.deltaTime;
            if (CurrentMoveTime >= MoveTime)
            {
                CurrentMoveTime = MoveTime;
                PositionOK      = true;

                Action.SetSuccess();
                Owner.BlackBoard.BusyAction = false;

                Owner.CoverStop();

                Owner.BlackBoard.Desires.CoverNear.Cover = null;

                //Debug.Log(Time.realtimeSinceStartup + " move ok");

                Release();
            }

            if (CurrentMoveTime > 0)
            {
                float progress = CurrentMoveTime / MoveTime;

                //Debug.Log("progress " + progress + " " + (v - Transform.position).magnitude + " pos " + Transform.position.x + ", " + Transform.position.z);

                if (Action.TypeOfLeave == AgentActionCoverLeave.E_Type.Right || Action.TypeOfLeave == AgentActionCoverLeave.E_Type.Left)
                {
                    Vector3 position = Mathfx.InterpolateCatmullRom(StartPositionHelper, StartPosition, FinalPosition, FinalPositionHelper, progress);
                    //Owner.CharacterController.Move( position - Transform.position );
                    Transform.position = position;                     // we decided not to use collision test during leaving of cover from left or right side
                }
                else if (Action.TypeOfLeave == AgentActionCoverLeave.E_Type.JumpUp)
                {
                    Transform.position = Vector3.Lerp(StartPosition, FinalPosition, progress);
                }
                else
                {
                    Vector3 position = Mathfx.Hermite(StartPosition, FinalPosition, progress);
                    if (Action.TypeOfLeave == AgentActionCoverLeave.E_Type.Jump)
                    {
                        Transform.position = position; // jump over without collisions
                    }
                    else                               // E_Type.Back
                    {
                        Owner.CharacterController.Move(position - Transform.position);
                    }
                }

                if (RotationOK == false)
                {
                    Owner.Transform.rotation = Quaternion.Lerp(StartRotation, FinalRotation, progress);

                    //Debug.Log ("AnimStateCoverLeave, RotationOK == false, Owner.Transform.rotation=" + Owner.Transform.rotation + ", progress=" + progress + ", time=" + Time.timeSinceLevelLoad);
                }
            }
        }

        if (EndOfStateTime <= Time.timeSinceLevelLoad)
        {
            // Owner.Transform.rotation = Owner.BlackBoard.Desires.Rotation;
            //Debug.Log(Time.realtimeSinceStartup + " release");
            Release();
        }
    }