Пример #1
0
    void FixedUpdate()
    {
        if (GameManager.isGamePaused())
        {
            return;
        }

        float vertical   = Input.GetAxisRaw(vAxisName);
        float horizontal = Input.GetAxisRaw(hAxisName);
        float shoot      = Input.GetAxisRaw(attackAxisName);

        Vector2 localUp = new Vector2(transform.up.x, transform.up.y);

        if (vertical != 0)
        {
            Vector2 engineForce = Vector2.Lerp(Vector2.zero, localUp * vertical * MaximalSpeed, Velocity * Time.deltaTime);
            rb.AddForce(engineForce);
            soundManager.PlayRide();
            animator.SetBool("isMoving", true);
        }
        else
        {
            animator.SetBool("isMoving", false);
        }

        SetupParticles(vertical);


        Vector2 velocityVector = rb.velocity.normalized;
        float   dot            = Vector2.Dot(velocityVector, localUp);

        if (horizontal != 0)
        {
            if (dot < 0 && rb.velocity.magnitude > 0 && vertical < 0)
            {
                rb.MoveRotation(rb.rotation + RotationSpeed * horizontal);
            }
            else
            {
                rb.MoveRotation(rb.rotation - RotationSpeed * horizontal);
            }
        }


        if ((dot != 1) && (dot != -1) && (velocityVector.magnitude != 0))
        {
            rb.velocity = Vector2.Lerp(rb.velocity, localUp * dot * rb.velocity.magnitude, FrictionScale * Time.deltaTime);
        }

        if (shoot != 0 && timer >= ReloadSpeed)
        {
            Shoot(localUp);
        }

        timer += Time.deltaTime;
    }
Пример #2
0
    void FixedUpdate()
    {
        if (GameManagerBoss.isGamePaused())
        {
            return;
        }

        transform.Translate(Vector3.up * Time.deltaTime * patrolSpeed);

        if (Vector3.Distance(transform.position, currentPatrolPoint.position) < 0.1f)
        {
            soundManager.PlayRide();
            animator.SetBool("isMoving", true);
            if (currentPatrolIndex + 1 < patrolPoints.Length)
            {
                currentPatrolIndex++;
            }
            else
            {
                currentPatrolIndex = 0;
            }

            currentPatrolPoint = patrolPoints[currentPatrolIndex];
        }

        Vector2    localUp        = new Vector2(transform.up.x, transform.up.y);
        Vector3    patrolPointDir = currentPatrolPoint.position - transform.position;
        float      angle          = Mathf.Atan2(patrolPointDir.y, patrolPointDir.x) * Mathf.Rad2Deg - 90;
        Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);

        transform.rotation = Quaternion.RotateTowards(transform.rotation, q, 180f);
        SetupParticles(1);

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

        if (distanceToTarget < chaseRange)
        {
            Vector3    targetDir = (target.position - transform.position).normalized;
            float      angleE    = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg - 90f;
            Quaternion q2        = Quaternion.AngleAxis(angleE, Vector3.forward);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, q2, 180f);
            transform.Translate(Vector3.up * Time.deltaTime * chaseSpeed);

            timer += Time.deltaTime;

            float distanceToPlayer = Vector3.Distance(transform.position, target.position);
            if (distanceToPlayer < attackRange)
            {
                Vector3    targetDir2 = target.position - transform.position;
                float      angleShoot = Mathf.Atan2(targetDir2.y, targetDir2.x) * Mathf.Rad2Deg - 90f;
                Quaternion q3         = Quaternion.AngleAxis(angleShoot, Vector3.forward);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, q3, 180f);

                int shoot = 1;
                if (shoot != 0 && timer >= ReloadSpeed)
                {
                    RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up, attackRange);
                    Shoot(localUp);
                }
            }
        }
    }