Beispiel #1
0
    public string GetCollisionStateString()
    {
        List <Collider2D> contactColliders = new List <Collider2D>();

        _capsuleCollider.GetContacts(contactColliders);

        List <string> colliderStrings = new List <string>();

        foreach (var collider in contactColliders)
        {
            if (collider.gameObject == gameController.Player.gameObject || collider.gameObject == this.gameObject)
            {
                continue;
            }

            ITimeTracker timeTracker = GameController.GetTimeTrackerComponent(collider.gameObject);
            if (timeTracker != null)
            {
                colliderStrings.Add(timeTracker.ID.ToString());
            }
            else
            {
                colliderStrings.Add($"U{collider.GetInstanceID().ToString()}");
            }
        }

        colliderStrings.Sort();

        return(string.Join(",", colliderStrings));
    }
Beispiel #2
0
    private void FixedUpdate()
    {
        List <Collider2D> lst = new List <Collider2D>();
        int x = _col.GetContacts(lst);

        foreach (Collider2D c in lst)
        {
            if (c.gameObject.tag == "Terrain")
            {
                player.grounded = true;
                return;
            }
        }
        player.grounded = false;
    }
    bool FeetOnFloor()
    {
        //footBox may or may not be already initialized, so lets just make sure it is.
        //note to future self: as an optimisation you could take out this check once you're sure
        //that "void Start() always executes before void Update() does its first loop."
        if (!footBox)
        {
            footBox = gameObject.GetComponent <CapsuleCollider2D>();
        }
        Collider2D[] colliders = new Collider2D[5];
        footBox.GetContacts(colliders);
        if (colliders[0])
        {
            return(true);
        }

        return(false);
    }
Beispiel #4
0
        private void UpdateMovementState()
        {
            var contactCount = _Collider.GetContacts(Contacts);

            for (int i = 0; i < contactCount; i++)
            {
                // If we are moving directly towards an object (or within 30 degrees of it), we are pushing it.
                if (Vector2.Angle(Contacts[i].normal, _Movement) > 180 - 30)
                {
                    Play(_Push);
                    return;
                }
            }

            var isRunning = Input.GetButton("Fire3");// Left Shift by default.

            Play(isRunning ? _Run : _Walk);
        }
Beispiel #5
0
        private void UpdateMovementState()
        {
            var contactCount = _Collider.GetContacts(Contacts);

            for (int i = 0; i < contactCount; i++)
            {
                // 如果我们直接向一个物体移动(或在30度范围内),我们就是在推它.
                if (Vector2.Angle(Contacts[i].normal, _Movement) > 180 - 30)
                {
                    Play(_Push);
                    return;
                }
            }

            var isRunning = Input.GetButton("Fire3");// 默认左Shift

            Play(isRunning ? _Run : _Walk);
        }
Beispiel #6
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Collider2D[] collider2Ds = new Collider2D[5];
        if (cc.GetContacts(collider2Ds) > 0)
        {
            if (other.gameObject.CompareTag("Meteore") && !asteroidAlreadyCollided.Contains(other.GetInstanceID()))
            {
                other.gameObject.GetComponent <Asteroid>().applyDmg(dmg * totalMultiplier);
                if (!CharacterController.Instance.hasPiercingShot)
                {
                    Destroy(gameObject);
                }
                else
                {
                    if (CharacterController.Instance.hasAutoGuidShot)
                    {
                        target = Vector3.zero;
                    }
                }

                asteroidAlreadyCollided.Add(other.GetInstanceID());
            }
        }

        if (CharacterController.Instance.hasAutoGuidShot && other.gameObject.CompareTag("Meteore") &&
            target == Vector3.zero &&
            !asteroidAlreadyCollided.Contains(other.GetInstanceID()))
        {
            asteroidAlreadyCollided.Add(other.GetInstanceID());
            target = other.transform.position;
        }

        if (CharacterController.Instance.hasBouncingShot && other.gameObject.CompareTag("Wall"))
        {
            //TODO
            //If mur Top ou Bot change Y
            //If mur Right ou Left change X
        }
    }
Beispiel #7
0
        private void UpdateMovementState()
        {
            var contactCount = _Collider.GetContacts(Contacts);

            for (int i = 0; i < contactCount; i++)
            {
                // If we are moving directly towards an object (or within 30 degrees of it), we are pushing it.
                if (Vector2.Angle(Contacts[i].normal, _Movement) > 180 - 30)
                {
                    _State = State.Push;
                    return;
                }
            }

            if (Input.GetButton("Fire3"))// Left Shift by default.
            {
                _State = State.Run;
            }
            else
            {
                _State = State.Walk;
            }
        }