Beispiel #1
0
        public Vector3 getPosInTail(SoulAvenger.Character chara)
        {
            bool useLeft = leftCharacterTail.Contains(chara);

            List <SoulAvenger.Character> cTrail = useLeft?leftCharacterTail:rightCharacterTail;

            BoxCollider myFeetsCollider = getFeet().GetComponent <BoxCollider>();
            Vector3     pos             = myFeetsCollider.transform.localToWorldMatrix.MultiplyPoint(myFeetsCollider.center);

            pos.y = myFeetsCollider.transform.position.y;
            float xDimension = myFeetsCollider.size.x * 0.5f;

            for (int i = 0; i < cTrail.Count; i++)
            {
                SoulAvenger.Character c = cTrail[i];

                BoxCollider cFeetsCollider = c.getFeet().GetComponent <BoxCollider>();

                if (c != chara)
                {
                    xDimension += cFeetsCollider.size.x;
                }
                else
                {
                    xDimension += (cFeetsCollider.size.x * 0.5f + cFeetsCollider.center.x);
                    break;
                }
            }

            float sizeFactor = useLeft?-1.0f:1.0f;

            pos.x += xDimension * sizeFactor;

            return(pos);
        }
Beispiel #2
0
        //true if the character moves, false if is colliding so it has already reach the target
        public bool moveToTarget(SoulAvenger.Character target, float movementSpeed, bool keepInArena)
        {
            Vector3 current3dPos = getFeet().position;
            Vector3 target3dPos  = target.getFeet().position;
            Vector3 diff         = target3dPos - current3dPos;

            diff.z = 0;

            if (feetsAreColliding(target))
            {
                SoulAvenger.Character.FACING currentF = (diff.x > 0)?SoulAvenger.Character.FACING.RIGHT:SoulAvenger.Character.FACING.LEFT;
                currentFacing = currentF;
                return(false);
            }

            tk2dAnimatedSprite sprite = GetComponent <tk2dAnimatedSprite>();

            movementSpeed *= sprite.localTimeScale;
            Vector3 velocity = diff; velocity.Normalize(); velocity *= movementSpeed * Time.deltaTime;

            Vector3 newPos = current3dPos + velocity;

            tryToMove(newPos, keepInArena);
            return(true);
        }
Beispiel #3
0
        public bool feetsAreColliding(SoulAvenger.Character target)
        {
            BoxCollider myFeets     = this.getFeet().GetComponent <BoxCollider>();
            BoxCollider targetFeets = target.getFeet().GetComponent <BoxCollider>();

            return(SoulAvenger.CollisionDetection.Test2D(myFeets, targetFeets));
        }
Beispiel #4
0
        public void pushToTail(SoulAvenger.Character c)
        {
            Vector3 CharPos = c.getFeet().position;
            Vector3 myPos   = this.getFeet().position;

            Vector3 diff = CharPos - myPos;

            if (diff.x <= 0.0f)
            {
                leftCharacterTail.Add(c);

                while (leftCharacterTail.Contains(null))
                {
                    leftCharacterTail.Remove(null);
                }

                leftCharacterTail.Sort(
                    delegate(SoulAvenger.Character c1, SoulAvenger.Character c2)
                {
                    float d1 = Vector3.Distance(this.getFeet().transform.position, c1.getFeet().transform.position);
                    float d2 = Vector3.Distance(this.getFeet().transform.position, c2.getFeet().transform.position);
                    return((d1 < d2)?-1:1);
                }
                    );
            }
            else
            {
                rightCharacterTail.Add(c);

                while (leftCharacterTail.Contains(null))
                {
                    leftCharacterTail.Remove(null);
                }

                rightCharacterTail.Sort(
                    delegate(SoulAvenger.Character c1, SoulAvenger.Character c2)
                {
                    float d1 = Vector3.Distance(this.getFeet().transform.position, c1.getFeet().transform.position);
                    float d2 = Vector3.Distance(this.getFeet().transform.position, c2.getFeet().transform.position);
                    return((d1 < d2)?-1:1);
                }
                    );
            }
        }