Пример #1
0
        private void OnCollisionEnter(Collision collision)
        {
            bool      dealed = true;
            Transform otherPlayer;
            Transform thisPlayer;

            switch (collision.collider.tag)
            {
            case "Ball":
                player.AddPower(hitBallPower);
                ServerSend.StageObjectInfo(new StageObjectPair {
                    category = player.category, id = player.id
                }, nameof(player.Power), player.Power);
                Bounce(collision.transform, 1.0f);
                break;

            case "Bar":
                player.AddPower(hitBarPower);
                ServerSend.StageObjectInfo(new StageObjectPair {
                    category = player.category, id = player.id
                }, nameof(player.Power), player.Power);
                otherPlayer = collision.transform.parent.parent;
                thisPlayer  = center.parent;
                Bounce(otherPlayer, 5.0f);
                Bounce(thisPlayer, GetDirection(otherPlayer, thisPlayer), 5.0f);
                break;

            case "Player":
                Bounce(collision.transform, 3.0f);
                break;

            default:
                dealed = false;
                break;
            }
            if (!dealed && collision.gameObject.TryGetComponent(out BaseStageObject obj))
            {
                switch (obj.category)
                {
                case StageObjectCategory.Dynamic:
                    Bounce(collision.transform, 1.0f, ForceMode.VelocityChange);
                    break;

                case StageObjectCategory.Static:
                    thisPlayer = center.parent;
                    Bounce(thisPlayer, GetDirection(collision.transform, thisPlayer), 2.0f);
                    break;

                case StageObjectCategory.Goal:
                case StageObjectCategory.Other:
                default:
                    break;
                }
            }
        }
Пример #2
0
        private void FixedUpdate()
        {
            //移动
            float h           = buffer[InputType.rotate];
            float accelerator = buffer[InputType.move];

            //Debug.Log(buffer[InputType.move]);
            rd.AddForce(accelerator * transform.forward * force);
            if (rd.velocity.magnitude >= currentMaxSpeed)
            {
                rd.velocity = rd.velocity.normalized * currentMaxSpeed;
            }

            transform.Rotate(0, h * rotateSpeedFactor, 0, Space.Self);

            //鼠标
            //旧
            //Vector3 rDir = new Vector3(buffer[InputType.mouseX], 0, buffer[InputType.mouseY]);
            //if(rDir != Vector3.zero)
            //{
            //    Vector3 nDir = rDir.normalized;
            //    transform.forward = nDir;
            //}

            //新(平滑旋转)
            Rotate(transform, buffer[InputType.mouseX], buffer[InputType.mouseY], 0.2f);


            //转bar
            if (!isBarRotate && buffer[InputType.barRotate] > 0)
            {
                isBarRotate = true;
            }

            if (isBarRotate)
            {
                for (int i = 0; i < player.barList.Count; i++)
                {
                    Bar current = player.barList[i];
                    step += barSpeedFactor;
                    current.transform.localPosition = Vector3.Lerp(current.original, current.Next.original, step);
                }
                if (step > 1)
                {
                    step = 0;
                    Vector3 firstOriginal = player.barList[0].original;
                    for (int i = 0; i < player.barList.Count - 1; i++)
                    {
                        Bar current = player.barList[i];
                        current.original = current.Next.original;
                    }
                    player.barList[0].Previous.original = firstOriginal;
                    isBarRotate = false;
                }
            }

            if (buffer[InputType.charge] > 0)
            {
                player.AddPower(player.powerPerSecond * Time.fixedDeltaTime);
                ServerSend.StageObjectInfo(new Pair {
                    category = player.category, id = player.id
                }, nameof(player.Power), player.Power);
                if (player.IsMaxPower)
                {
                    Debug.Log($"玩家{player.id} 洪荒之力已满 大招充能完毕");
                }
                currentMaxSpeed = chargeMaxSpeed;
            }
            else
            {
                if (currentMaxSpeed != originMaxSpeed)
                {
                    currentMaxSpeed = originMaxSpeed;
                }
            }

            //大招
            if (player.IsMaxPower && buffer[InputType.ultimate] > 0)
            {
                if (ultimate != null && !ultimate.IsOn)
                {
                    ultimate.Enter();
                }
                player.ResetPower();
                ServerSend.StageObjectMethod(new Pair {
                    category = player.category, id = player.id
                }, nameof(player.ResetPower));
            }

            if (ultimate != null && ultimate.IsOn)
            {
                ultimate.FixedUpdate();
            }

            RefreshBuffer();
        }