Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     target = GameObject.FindGameObjectWithTag("Player").transform;
     rb     = GetComponent <Rigidbody>();
     agent  = agentTransform.GetComponent <NavMeshAgent>();
     agent.updatePosition = false;
     agent.updateRotation = false;
     path              = new NavMeshPath();
     state             = LilRobotState.IDLE;
     headPosition      = head.localPosition;
     lastLocalRotation = head.localRotation;
     recoverResetTime  = recoverTime;
 }
Exemplo n.º 2
0
    private void FixedUpdate()
    {
        /**Manual Control**/

        /*float x = Input.GetAxis("Horizontal");
         * float y = Input.GetAxis("Vertical");*/
        /****/

        if (!agent.isOnNavMesh)
        {
            agent.enabled = false;
            agent.enabled = true;
        }

        float distance = Vector3.Distance(target.position, transform.position);

        switch (state)
        {
        case LilRobotState.IDLE:
            /**Manual Control**/

            /*rb.AddForce(Vector3.right * x * 10);
             * rb.AddForce(Vector3.forward * y * 10);*/
            /****/
            //rb.AddForce(transform.InverseTransformDirection(rb.velocity));

            if (distance < detectionDistance && agent.isOnNavMesh)
            {
                state = LilRobotState.ATTACK;
            }
            break;

        case LilRobotState.ATTACK:
            agent.CalculatePath(target.position, path);
            Vector3 dir = path.corners[1] - transform.position;
            //rb.AddForce(dir.normalized * 0.3f);
            rb.AddForce(dir.normalized * maxSpeed * Time.deltaTime);
            if (distance > detectionDistance + 5f)
            {
                state = LilRobotState.IDLE;
            }
            else if (distance < jumpDistance)
            {
                state = LilRobotState.JUMP;
            }
            break;

        case LilRobotState.JUMP:
            rb.AddForce(Vector3.up * jumpForce);
            state = LilRobotState.RECOVER;
            break;

        case LilRobotState.RECOVER:
            if (recoverTime > 0f)
            {
                //rb.AddForce(transform.InverseTransformDirection(rb.velocity));
                recoverTime -= Time.deltaTime;
            }
            else
            {
                recoverTime = recoverResetTime;
                state       = LilRobotState.IDLE;
            }
            break;

        default:
            break;
        }
    }