Esempio n. 1
0
    private void OnActiveUpdate()
    {
        targetPosition         = transform.position;
        rigidbody.gravityScale = gravityScale;
        rigidbody.velocity     = -transform.up * speed;


        Vector2 direction = movementInput.normalized;

        if (direction.sqrMagnitude > 0.4)
        {
            targetDirection = direction;
        }


        var target  = Quaternion.LookRotation(targetDirection, Vector3.forward);
        var current = Quaternion.Euler(0f, 0f, rigidbody.rotation);
        var amount  = rotationSpeed * Time.deltaTime / Quaternion.Angle(target, current);

        rigidbody.SetRotation(Quaternion.Slerp(current, target, amount).eulerAngles.z);

        //rigidbody.SetRotation(rigidbody.rotation + input * 90f * Time.deltaTime);



        if (Vector2.Distance(lastPosition, transform.position) > 0.5f)
        {
            currentRoot.AddPoint(transform.position);
            currentIndex = currentRoot.GetPointCount();
            lastPosition = transform.position;
        }
        currentRoot.UpdateLastPosition(transform.position);


        if (IsInvincible == false && this.rootManager.CheckForCollision(transform.position, 0.5f))
        {
            gameManager.SetState(GameState.Dead);
            rigidbody.velocity = Vector2.zero;
            SpawnImpact();
        }
    }
Esempio n. 2
0
    private void Awake()
    {
        rootManager       = FindObjectOfType <RootManager>();
        resourceManager   = FindObjectOfType <ResourceManager>();
        rigidbody         = GetComponent <Rigidbody2D>();
        this.IsInvincible = false;

        gameManager = GameManager.GetInstance();

        Vector2 start  = new Vector2(0, 0);
        Vector2 target = Vector2.right;

        targetRotation = rigidbody.rotation;

        if (currentRoot == null)
        {
            currentRoot = rootManager.GetCurrent();
            if (currentRoot == null)
            {
                rootManager.CreateNewVisual(transform.position);
                currentRoot = rootManager.GetCurrent();
                // Create a second point that will be move to the player's location
                currentRoot.AddPoint(transform.position);
                currentIndex = currentRoot.GetPointCount();
                lastPosition = transform.position;
            }
        }

        input = new PlayerInput();
        input.SeedControls.Movement.performed += (ctx) => movementInput = ctx.ReadValue <Vector2>();

        input.SeedControls.Kill.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Active)
            {
                gameManager.SetState(GameState.Dead);
            }
        };

        input.SeedControls.Select.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Retreat)
            {
                if (resourceManager.IsWaterDrained == false)
                {
                    gameManager.SetState(GameState.Aim);
                }
            }
            else if (gameManager.ActiveState == GameState.Aim)
            {
                ExitRetreat();
            }
        };

        input.SeedControls.Cancel.performed += (ctx) =>
        {
            if (gameManager.ActiveState == GameState.Aim)
            {
                gameManager.SetState(GameState.Retreat);
            }
        };
    }