Esempio n. 1
0
 private void UpdateColliderBounds()
 {
     currentColliderBounds             = new ColliderBounds();
     currentColliderBounds.bottomLeft  = associatedCollider.bounds.min;
     currentColliderBounds.topRight    = associatedCollider.bounds.max;
     currentColliderBounds.bottomRight = new Vector3(associatedCollider.bounds.max.x, associatedCollider.bounds.min.y);
     currentColliderBounds.topLeft     = new Vector3(associatedCollider.bounds.min.x, associatedCollider.bounds.max.y);
 }
Esempio n. 2
0
    public NavigationInfo(Transform transform, BoxCollider2D boxCollider2D, TransitionFloorType type)
    {
        this.transform     = transform;
        this.boxCollider2D = boxCollider2D;
        this.type          = type;
        colliderBounds     = new ColliderBounds();

        UpdateColliderBounds(boxCollider2D);
    }
Esempio n. 3
0
    private void Update()
    {
        if (_isDead)
        {
            return;
        }
        colliderBounds = new ColliderBounds(_collider.bounds);
        Falling();

        Vector2 targetVector = Target.position - transform.position;

        _targetDir = targetVector.normalized;

        if (_targetDir.x > 0)
        {
            _renderer.flipX = true;
        }
        else
        {
            _renderer.flipX = false;
        }

        float dist = Vector2.SqrMagnitude(targetVector);

        if (dist > runDist * runDist)
        {
            Walk();
        }
        else if (dist > attackDist * attackDist)
        {
            Run();
        }
        else
        {
            ReadyAttack();
        }

        if (_timeCount > 0)
        {
            _timeCount -= Time.deltaTime;
        }

        if (CheckObstacle())
        {
            return;
        }



        if (_isAttack)
        {
            _velocity = 0;
        }

        transform.Translate(new Vector2(_velocity, 0) * Time.deltaTime);
    }
Esempio n. 4
0
    /// <summary>
    /// This should be called by our HitboxManager
    /// </summary>
    public override void UpdateBoundsOfCollider()
    {
        base.UpdateBoundsOfCollider();

        ColliderBounds b      = new ColliderBounds();
        Vector2        origin = this.transform.position + new Vector3(boxColliderPosition.x, boxColliderPosition.y);

        b.topLeft     = origin + Vector2.up * boxColliderSize.y / 2 - Vector2.right * boxColliderSize.x / 2;
        b.topRight    = origin + Vector2.up * boxColliderSize.y / 2 + Vector2.right * boxColliderSize.x / 2;
        b.bottomLeft  = origin - Vector2.up * boxColliderSize.y / 2 - Vector2.right * boxColliderSize.x / 2;
        b.bottomRight = origin - Vector2.up * boxColliderSize.y / 2 + Vector2.right * boxColliderSize.x / 2;

        this.bounds = b;
    }
Esempio n. 5
0
 public TransitionFloor(Floor firstFloor, Floor secondFloor, Transform transform,
                        ColliderBounds colliderBounds,
                        TransitionFloorType type)
 {
     floors = new List <Floor>()
     {
         firstFloor,
         secondFloor
     };
     floors.Sort((floor, floor1) => floor.number - floor1.number);
     this.transform      = transform;
     this.type           = type;
     this.colliderBounds = colliderBounds;
 }
Esempio n. 6
0
    public void Move(float moveDir)
    {
        colliderBounds = new ColliderBounds(_collider.bounds);
        Falling();

        if (_iscounter || _isDash)
        {
            footstep.StopFootstep();
            if (_isDash)
            {
                _slideValue -= Time.deltaTime * decayValue;
                _slideValue  = Mathf.Clamp(_slideValue, 0, 100);
                float dir = 1;
                if (_renderer.flipX)
                {
                    dir = -1;
                }
                transform.Translate(new Vector2(_slideValue * 3 * dir * Time.deltaTime, 0));
            }
            return;
        }

        var targetVelocity = CalculateVelocity(moveDir);

        _animator.SetBool("Run", true);
        if (moveDir > 0)
        {
            footstep.StartFootstep();
            _renderer.flipX    = false;
            Effects.localScale = new Vector3(1, 1, 1);
        }
        else if (moveDir < 0)
        {
            footstep.StartFootstep();
            Effects.localScale = new Vector3(-1, 1, 1);
            _renderer.flipX    = true;
        }
        else
        {
            footstep.StopFootstep();
            _animator.SetBool("Run", false);
            _animator.SetBool("Idle", true);
        }

        _velocity = new Vector2(targetVelocity, 0);
        if (!CheckObstacle())
        {
            transform.Translate(new Vector2(_velocity.x, 0) * Time.deltaTime);
        }
    }
Esempio n. 7
0
    public void ChangeDirectionBasedOffCollider(ColliderBounds bounds)
    {
        switch (bounds)
        {
        case ColliderBounds.TOP:
            direction.y = -1;
            break;

        case ColliderBounds.BOTTOM:
            direction.y = 1;
            break;

        case ColliderBounds.LEFT:
            direction.x = -1;
            break;

        case ColliderBounds.RIGHT:
            direction.x = 1;
            break;
        }
    }