Пример #1
0
        protected override bool isPlay(CollisionActionResult result)
        {
            var baseResult = base.isPlay(result);
            var haptic     = m_HapticConfig == null || m_HapticConfig.IsHapticEnabled;

            Debug.Log("base: " + baseResult + ", haptic: " + haptic);
            return(baseResult && haptic);
        }
Пример #2
0
 public override CollisionActionResult OnCollisionAction(CollisionActionResult result)
 {
     if (isHapticable(result))
     {
         Debug.Log("Feedback Haptic: " + result.Other.gameObject.name);
         // Rumble(500); // 500 ms
         // pattern: off, on, off, ...(ms), repeat: -1 is oneshot.
         m_HapticFeedback.Rumble(HapticData.CreateFrom(result.Sound));
         // StartCoroutine("Restore");
     }
     return(result);
 }
Пример #3
0
        /// <summary>
        /// テーブルはServer管理していないので独自の物理計算はせずにPhysics Materialで対応する方向で・・・テーブルは常時isKinematicオンでOK
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public override CollisionActionResult OnCollisionAction(CollisionActionResult result)
        {
            if (Prefab.Ball.IsClone(result.Other.gameObject))
            {
                //Debug.Log("A ball hit the table tennis table.");

                /*var body = result.Other.gameObject.GetComponent<Rigidbody>();
                 * Debug.Log("T_Before"+body.velocity);
                 * if (Mathf.Abs(body.velocity.y) <= 0.5f)
                 * {
                 *  result.Other.gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(0f, Mathf.Abs(body.velocity.z) * body.mass * 1f / 1.414f, 0f), ForceMode.Impulse);
                 *  Debug.Log("modeA");
                 * }
                 * else
                 * {
                 *  result.Other.gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(0f, Mathf.Abs(body.velocity.y) * body.mass * 0.8f, 0f), ForceMode.Impulse);
                 *  Debug.Log("modeB");
                 * }*/
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 追加 プレイヤーに当たったオブジェクトがボールだった場合は振動して上方向に力を加える
        /// LocalPlayerController に書かれていた処理を持ってきました。
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public override CollisionActionResult OnCollisionAction(CollisionActionResult result)
        {
            Debug.Log("Hit:" + result.Other.gameObject.name); // ぶつかった相手の名前を取得
            float speedZ = -1.414f;                           //前方向
            float speedY = 1f;                                //上方向
            float speed  = 12f;

            if (stage == null)
            {
                stage = Prefab.Stage.FindClone();
            }

            if (Prefab.Ball.IsClone(result.Other.gameObject)) // if (collision.gameObject.name == "Ball(Clone)")
            {
                var     body   = result.Other.gameObject.GetComponent <Rigidbody>();
                Vector3 Force  = new Vector3(0, speedY, speedZ).normalized *body.mass *speed * 1000f / 3600f;
                Vector3 Force2 = (stage.transform.position - body.transform.position) * body.mass * speed * 1000f / 3600f;
                body.velocity        = Vector3.zero; //ボールの速度をゼロにする
                body.angularVelocity = Vector3.zero; //ボールにかかっている回転を一度ストップ
                result.Other.gameObject.GetComponent <Rigidbody>().AddForce(Force, ForceMode.Impulse);
                result.Other.gameObject.GetComponent <Rigidbody>().AddForce(new Vector3(Force2.x * 0.5f, 0f, 0f), ForceMode.Impulse);
            }
            return(result);
        }
 protected override bool isPlay(CollisionActionResult result)
 {
     return(base.isPlay(result) && Prefab.Ball.IsClone(result.Other.gameObject));
 }
Пример #6
0
 protected virtual bool isHapticable(CollisionActionResult result)
 {
     return(m_IsHapticable && result.IsCollisionHapticable && result.Other.gameObject.GetComponent <Hapticable>() != null);
 }
        /// <summary>
        /// 追加 プレイヤーに当たったオブジェクトがボールだった場合は振動して上方向に力を加える
        /// LocalPlayerController に書かれていた処理を持ってきました。
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public override CollisionActionResult OnCollisionAction(CollisionActionResult result)
        {
            Debug.Log("Hit:" + result.Other.gameObject.name); // ぶつかった相手の名前を取得
            //float speedZ = 1.414f; //physics version.1用
            float speedZ    = 0.414f;
            float speedY    = 1f;
            float speedX    = 0f;
            float speedP    = 12f;
            float addSpeedP = 0f;

            //float coefficient = 1.0f;

            if (Prefab.Ball.IsClone(result.Other.gameObject)) // if (collision.gameObject.name == "Ball(Clone)")
            {
                var body = result.Other.gameObject.GetComponent <Rigidbody>();
                body.useGravity = true;
                Vector3 Force;
                Vector3 stagePosition;

                if (stage != null)
                {
                    stage         = Prefab.Stage.FindClone();
                    stagePosition = stage.transform.position;
                }

                BallRotation br = GetComponent <BallRotation>(); //ラケットの速度を取得
                if (br.RacketSpeed() <= 0.5f)                    //ラケットが遅いとき
                {
                    addSpeedP = 0.5f;
                }
                else if (br.RacketSpeed() > 2.0f)  //ラケットが速すぎるとき
                {
                    addSpeedP = 2f;
                }
                else
                {
                    addSpeedP = (br.RacketSpeed() - 0.5f) * 2f / 1.5f;  //ラケットがいい感じの時
                }

                /*if (br.playModeRotation() == 1)
                 * {
                 *  speedX = -0.3f;
                 * }
                 * else if (br.playModeRotation() == 2)
                 * {
                 *  speedX = 0.3f;
                 * }
                 * else
                 * {
                 *  speedX = 0.0f;
                 * }*/

                /**physics version.1
                 * Force = new Vector3(0f, speedY, speedZ).normalized * v0;
                 * body.velocity = Vector3.zero;
                 * result.Other.gameObject.GetComponent<Rigidbody>().AddForce(Force, ForceMode.Impulse);
                 * result.Other.gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(transform.forward.x,0f,0f)*v0, ForceMode.Impulse);
                 **/

                if (stage == null)
                {
                    stagePosition = Vector3.zero;
                }
                else if (stage != null)
                {
                    float Dif = transform.position.y - stage.transform.position.y;
                    if (Dif <= 0.2)
                    {
                        speedP = 12f;
                    }
                    else if (Dif > 0.2 && Dif <= 0.4)
                    {
                        speedP = 11f;
                    }
                    else if (Dif > 0.4 && Dif <= 0.6)
                    {
                        speedP = 10f;
                    }
                    else
                    {
                        speedP = 9f;
                    }
                }


                float speed = (speedP + addSpeedP) * 1000f / 3600f;
                float v0    = body.mass * speed;
                //physics version.2
                Force                = new Vector3(0f, transform.forward.y + speedY, transform.forward.z + speedZ).normalized *v0;
                body.velocity        = Vector3.zero;
                body.angularVelocity = Vector3.zero;
                result.Other.gameObject.GetComponent <Rigidbody>().AddForce(Force, ForceMode.Impulse);
                result.Other.gameObject.GetComponent <Rigidbody>().AddForce(new Vector3(transform.forward.x + speedX, 0f, 0f) * v0, ForceMode.Impulse);
            }
            return(result);
        }