Example #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 currentPos      = rbody.position;
        float   horizontalInput = Input.GetAxis("Horizontal");
        float   verticalInput   = Input.GetAxis("Vertical");
        Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);

        inputVector = Vector2.ClampMagnitude(inputVector, 1);
        Vector2 movement = inputVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);
        // print("Temp:" + tilemap.WorldToCell(transform.position));
        // print("MouseTemp:" + tilemap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)));
        // Vector3 thing = grid.WorldToCell(rbody.position);
        // Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        // Vector3Int cellCoords = grid.WorldToCell(mousePosition);
        // Vector3 midPos = grid.CellToWorld(cellCoords);
        //
        //
        // Vector3Int scrubPos = grid.WorldToCell(midPos);
        // scrubPos.z = 0;
        // print("GridMouseY: " + mousePosition.y);
        //print("GridMouseX: " + grid.WorldToCell(scrubPos));
        Vector3Int cellMousePosition = tilemap.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition));

        cellMousePosition.z = 0;
        playerReticle.transform.position = tilemap.GetCellCenterWorld(cellMousePosition);
    }
Example #2
0
    // public void EntityEnteredRange(GameObject go) {
    //   if (go.tag == hitboxTrigger.tag) return;
    // }
    //
    // public void EntityExitedRange(GameObject go) {
    //   if (go.tag == hitboxTrigger.tag) return;
    // }

    void FixedUpdate()
    {
        if (movementPath.Count > 0)
        {
            Vector2 currWorldPos = rigidbody.position;
            // Find hearth and attack it
            Vector3 targetWorldPos = movementPath[0];
            if (variantPos)
            {
                targetWorldPos += tilePositionVariance;
            }
            if (Vector3.Distance(movementPath[0], transform.position) < 0.02f && movementPath.Count >= 1)
            {
                movementPath.RemoveAt(0);
                if (variantPos)
                {
                    tilePositionVariance = new Vector3(Random.Range(-0.12f, 0.12f), Random.Range(-0.12f, 0.12f), 0f);
                }
            }

            Vector2 inputVector = new Vector2(targetWorldPos.x - currWorldPos.x, targetWorldPos.y - currWorldPos.y);
            inputVector = Vector2.ClampMagnitude(inputVector, 1);
            if (isoRend != null)
            {
                isoRend.SetDirection(inputVector);
            }
            Vector2 movement = inputVector * movementSpeed;
            Vector2 newPos   = currWorldPos + movement * Time.fixedDeltaTime;
            rigidbody.MovePosition(newPos);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!_stats.IsDead)
        {
            if (Time.time > _nextAttack)
            {
                if (Input.GetButtonDown("Fire1"))
                {
                    Vector3 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Vector3 origin   = transform.position + _muzzle_offset;
                    Vector3 shootDir = (clickPos - origin);
                    shootDir.z = 0;
                    shootDir.Normalize();


                    isoRenderer.AttackDirection(shootDir);
                    GameObject p;
                    p = Instantiate(projectile, origin + (shootDir * 0.4f), Quaternion.LookRotation(shootDir));
                    p.GetComponent <Rigidbody2D>().velocity = shootDir * speed;
                    p.GetComponent <ProjectileMove>().setCharacterTag("Player");
                    p.GetComponent <ProjectileMove>().setStartPos(origin);
                    _nextAttack = Time.time + 0.5f;
                }
                else
                {
                    Vector2 currentPos      = rbody.position;
                    float   horizontalInput = Input.GetAxis("Horizontal");
                    float   verticalInput   = Input.GetAxis("Vertical");
                    Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);
                    inputVector = Vector2.ClampMagnitude(inputVector, 1);
                    Vector2 movement = inputVector * movementSpeed;

                    if (Mathf.Abs(movement.magnitude) > 0)
                    {
                        _direction.x = movement.x;
                        _direction.y = movement.y;
                        _direction.Normalize();
                    }

                    Vector2 newPos = currentPos + movement * Time.fixedDeltaTime;
                    isoRenderer.SetDirection(movement);
                    rbody.MovePosition(newPos);
                }
            }
        }
    }