Ejemplo n.º 1
0
 private void OnEnable()
 {
     npc        = this.GetComponent <NPC_Citizen1>();
     idleState  = this.GetComponent <IdleBasicState>();
     avoidState = this.GetComponent <AvoidState>();
     // Slightly delay meeting so NPCs don't start out directly meeting
 }
    // Update is called once per frame
    void Update()
    {
        this.transform.localPosition = new Vector3(0, 0, -dist);
        if (dist < targetDist)
        {
            dist += adjustSpeed * Time.deltaTime;
            if (dist > targetDist)
            {
                dist = targetDist;
            }
        }
        if (dist > targetDist)
        {
            dist -= adjustSpeed * Time.deltaTime;
            if (dist < targetDist)
            {
                dist = targetDist;
            }
        }

        if (state == AvoidState.locked)
        {
            return;
        }

        if (state == AvoidState.far)
        {
            targetDist += adjustSpeed * Time.deltaTime;
            state       = AvoidState.idle;
        }

        quiencojones = "";

        tocando = 0;
    }
Ejemplo n.º 3
0
    // Use this for initialization

    void Start()
    {
        Move_parameter_x          = 0;
        Move_parameter_x          = 0;
        playerController          = this;
        AttackTrigger             = 0;
        PlayerAnimation_parameter = 0;
        GhostShadow.ghostShadow.gameObject.GetComponent <GhostShadow>().enabled = false;

        debounce = true;
        CanMove  = true;
        AttackCollider_Small.SetActive(false);
        AttackCollider_Big.SetActive(false);
        AttackCollider_BigSkill.SetActive(false);
        CanAttack             = true;
        CancelAttackCoroutine = null;
        ResetStateCoroutine   = null;
        DoubleClickCoroutine  = null;
        FastRunCoroutine      = null;
        GetUpCoroutine        = null;
        AvoidDistance         = AvoidMaxDistance;
        FixBulletPos          = Bullet_pos.transform.position - transform.position;

        Weapons.transform.parent              = WeaponsBone;//--
        LightAccessoriesUp.transform.parent   = LightAccessoriesUpBone;
        LightAccessoriesDown.transform.parent = LightAccessoriesDownBone;

        attackState         = AttackState.Default;
        moveState           = MoveState.Idle;
        playerAnimatorState = PlayerAnimatorState.Movement;
        avoidState          = AvoidState.Default;
        jumpState           = JumpState.Jump;
    }
 // Use this for initialization
 void Start()
 {
     cam   = this.GetComponent <Camera> ();
     state = AvoidState.locked;
     dist  = targetDist = restDist;
     cols  = 0;
 }
Ejemplo n.º 5
0
    private void Avoid_DoubleClickFuntion(AvoidState avoidState, string InputKey)
    {
        if (CanDoubleClick)
        {
            InputKey_next = InputKey;
            nextClickTime = Time.time;
            if (nextClickTime - preClickTime > 0.1f && InputKey_next == InputKey_pre)
            {
                StopCoroutine(DoubleClickCoroutine);
                CanDoubleClick = false;

                /* moveState = MoveState.FastRunForward;
                 * IsFastRun = true;*/
                AvoidStateSelect(avoidState);
            }
        }
        else
        {
            InputKey_pre         = InputKey;
            preClickTime         = Time.time;
            CanDoubleClick       = true;
            DoubleClickCoroutine = DoubleClick(DoubleClickTime);
            StartCoroutine(DoubleClickCoroutine);
        }
    }
    /*
     * void OnCollisionEnter(Collision other) {
     *
     ++cols;
     *      state = AvoidState.far;
     *
     * }
     *
     * void OnCollisionExit(Collision other) {
     *
     *      --cols;
     *      if (cols == 0)
     *              state = AvoidState.idle;
     *
     * }*/


    void OnTriggerStay(Collider col)
    {
        if (state != AvoidState.locked)
        {
            state = AvoidState.far;             // as long as you are colliding with s/t, keep moving
        }
        tocando      = 1;
        quiencojones = col.name;
    }
Ejemplo n.º 7
0
 private void OnEnable()
 {
     npc             = this.GetComponent <NPC_Citizen1>();
     idleState       = this.GetComponent <IdleBasicState>();
     avoidState      = this.GetComponent <AvoidState>();
     _taskController = this.GetComponent <NPC_Task_Controller>();
     meetState       = this.GetComponent <MeetNPCState>();
     meetPlayerState = this.GetComponent <MeetPlayerState>();
 }
Ejemplo n.º 8
0
 private void OnEnable()
 {
     npc             = this.GetComponent <NPC_Citizen1>();
     idleState       = this.GetComponent <IdleBasicState>();
     avoidState      = this.GetComponent <AvoidState>();
     meetPlayerState = this.GetComponent <MeetPlayerState>();
     // Slightly delay meeting so NPCs don't start out directly meeting
     Invoke("ReadyToMeetAgain", meetingTime);
 }
Ejemplo n.º 9
0
    IEnumerator ResetState(float WaitTime)
    {
        yield return(new WaitForSeconds(WaitTime));

        playerAnimatorState = PlayerAnimatorState.Movement;
        avoidState          = AvoidState.Default;
        GhostShadow.ghostShadow.gameObject.GetComponent <GhostShadow>().enabled = false;
        IsFastRun = false;
        DamageObject.SetActive(true);
    }
    protected override void Move()
    {
        if (moveState == AvoidState.None)
        {
            // Look at target
            pawn.tf.LookAt(GameManager.instance.targetNode.tf.position);
            // Move forward
            pawn.tf.position += pawn.tf.forward * speed * Time.deltaTime;
            // If we CAN'T move forward, change to turn to avoid state
            if (!CanMoveForward())
            {
                moveState      = AvoidState.TurnToAvoid;
                enterStateTime = Time.time;
            }
        }
        else if (moveState == AvoidState.TurnToAvoid)
        {
            pawn.tf.Rotate(0, turnSpeed * Time.deltaTime, 0);

            if (CanMoveForward())
            {
                moveState      = AvoidState.MoveToAvoid;
                enterStateTime = Time.time;
            }
        }
        else if (moveState == AvoidState.MoveToAvoid)
        {
            // If you can move forward, do so for X seconds
            if (CanMoveForward())
            {
                // Move forward
                pawn.tf.position += pawn.tf.forward * speed * Time.deltaTime;

                // If Time is up
                if (Time.time >= enterStateTime + avoidMoveTime)
                {
                    // Go back to normal state
                    moveState      = AvoidState.None;
                    enterStateTime = Time.time;
                }
            }
            else
            {
                // Can't move forward, so go back to turning to avoid
                moveState      = AvoidState.TurnToAvoid;
                enterStateTime = Time.time;
            }
        }
    }
 public void reset()
 {
     targetDist = restDist;
     state      = AvoidState.locked;
 }
 public void unlock()
 {
     state = AvoidState.far;
 }
Ejemplo n.º 13
0
 protected virtual void OnEnable()
 {
     npc        = this.GetComponent <NPC_BaseClass>();
     idleState  = this;
     avoidState = this.GetComponent <AvoidState>();
 }
Ejemplo n.º 14
0
    private void AvoidStateSelect(AvoidState InputAvoidState)
    {
        UI_HP.Ui_HP.SP -= UI_HP.Ui_HP.SP_Max / UI_HP.Ui_HP.SP_Light.Length;
        UI_HP.Ui_HP.ConsumeSP();
        CanMove             = true;
        playerAnimatorState = PlayerAnimatorState.Avoid;
        DamageObject.SetActive(false);
        avoidStartTime = Time.time;
        switch (InputAvoidState)
        {
        case AvoidState.Forward:
            avoidState = InputAvoidState;
            animator.SetTrigger("Avoid_Forward");
            AvoidRotate = 0;
            break;

        case AvoidState.Back:
            avoidState = AvoidState.Back;
            animator.SetTrigger("Avoid_Back");
            AvoidRotate = 180;
            break;

        case AvoidState.Left:
            avoidState = AvoidState.Left;
            animator.SetTrigger("Avoid_Left");
            AvoidRotate = -90;
            break;

        case AvoidState.Right:
            avoidState = AvoidState.Right;
            animator.SetTrigger("Avoid_Right");
            AvoidRotate = 90;
            break;

        case AvoidState.ForwardLeft:
            avoidState = AvoidState.ForwardLeft;
            animator.SetTrigger("Avoid_ForwardLeft");
            AvoidRotate = -45;
            break;

        case AvoidState.ForwardRight:
            avoidState = AvoidState.ForwardRight;
            animator.SetTrigger("Avoid_ForwardRight");
            AvoidRotate = 45;
            break;

        case AvoidState.BackLeft:
            avoidState = AvoidState.BackLeft;
            animator.SetTrigger("Avoid_BackLeft");
            AvoidRotate = -135;
            break;

        case AvoidState.BackRight:
            avoidState = AvoidState.BackRight;
            animator.SetTrigger("Avoid_BackRight");
            AvoidRotate = 135;
            break;
        }
        AvoidEuler    = Quaternion.Euler(0, RotationX + AvoidRotate, 0);
        AvoidPosition = AvoidEuler * new Vector3(0, 0, AvoidDistance) + transform.position;
    }
Ejemplo n.º 15
0
 private void OnEnable()
 {
     npc         = this.GetComponent <NPC_BaseClass>();
     wanderState = this.GetComponent <WanderState>();
     avoidState  = this.GetComponent <AvoidState>();
 }
Ejemplo n.º 16
0
    void TerrainAvoid()
    {
        //If not already avoiding
        int layermask = 1 << 8;

        layermask = ~layermask;

        if (currentState != AIState.Avoiding)
        {
            // Look forward as far as avoidRange - if something other than the target is in the way, avoid
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, avoidRange, layermask))
            {
                //Set state to Avoiding and remember previous state
                previousState = currentState;
                currentState  = AIState.Avoiding;
                avoidState    = FindClearDirection();
                //Debug.Break();
            }
        }
        else
        {
            // If we are in avoid mode and not already breaking out, check twice as far out and set breakout time if clear
            RaycastHit hit;
            if (!Physics.Raycast(transform.position, transform.forward, out hit, avoidRange * breakOutFactor, layermask) && breakOutTime == 0)
            {
                breakOutTime = Time.time;
            }

            // If we are in breakout mode, breakOutTime will be valid otherwise it will be 0
            // If longer than a second since breakout activated, go back to previous mode
            if ((breakOutTime != 0) && (Time.time - breakOutTime >= breakOutAngle / 75))
            {
                currentState = previousState;
                avoidState   = AvoidState.Null;
                breakOutTime = 0;
            }
            else if ((breakOutTime != 0) && (Time.time - breakOutTime >= breakOutAngle / 100))
            {
                FireThrusters();
            }
            else
            {
                if (avoidState == AvoidState.Left)
                {
                    rotateInput = -1;
                    FireThrusters();
                }
                if (avoidState == AvoidState.Right)
                {
                    rotateInput = 1;
                    FireThrusters();
                }
                if (avoidState == AvoidState.AboutTurn)
                {
                    if (thrusting)
                    {
                        StopThrusters();
                    }
                    rigidbody.useGravity = false;
                    rotateInput          = 1;
                }
            }
        }
    }