示例#1
0
文件: TennisBall.cs 项目: MF-JIN/test
        void Reset()
        {
            if (playground.agentA.score > playground.levelOne && playground.agentB.score > playground.levelOne)
            {
            }

            var px = 8f; // Random.Range(-playground.HalfSize.x, playground.HalfSize.x) > 0 ? 8f : -8f;
            var py = 2f; //Random.Range(4f, playground.HalfSize.y);//
            var pz = 0f; // Random.Range(-playground.HalfSize.z, playground.HalfSize.z);

            transform.localPosition = new Vector3(px, py, pz);

            var vx = -12.6f; // (px > 0f ? -1f:1f) * Random.Range(velocityMinInit.x, velocityMax.x); // * 14f; //
            var vy = 3.5f;   // Random.Range(velocityMinInit.y, velocityMax.y); // 3.5f;//
            var vz = -3f;    // Random.Range(velocityMinInit.z, velocityMax.z);

            rb.velocity = new Vector3(vx, vy, vz);

            playground.agentA.EndEpisode();
            playground.agentB.EndEpisode();
            playground.agentA2.EndEpisode();
            playground.agentB2.EndEpisode();
            lastFloorHit = FloorHit.Service;
            lastHitAgent = null;
            net          = false;
        }
示例#2
0
文件: TennisBall.cs 项目: MF-JIN/test
        void OnCollisionEnter(Collision collision)
        {
            currentCollision = collision;
            if (CollisionEnter != null)
            {
                CollisionEnter(collision, "Enter");
            }

            if (collision.gameObject.CompareTag("iWall"))
            {
                if (collision.gameObject.name == "wallA")
                {
                    // Agent A hits into wall or agent B hit a winner
                    if ((lastHitAgent && !lastHitAgent.invertX) ||
                        lastFloorHit == FloorHit.FloorAHit)
                    {
                        if (lastHitAgent && lastHitAgent.invertX) // agent B hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent A hits into wall
                        {
                            AgentBWins();
                        }
                    }
                    // Agent B hits long
                    else // if (lastAgentHit == AgentRole.B)
                    {
                        AgentAWins();
                    }
                    Reset();
                }
                else if (collision.gameObject.name == "wallB")
                {
                    // Agent B hits into wall or agent A hit a winner
                    if ((lastHitAgent && lastHitAgent.invertX) ||
                        lastFloorHit == FloorHit.FloorBHit)
                    {
                        if (lastHitAgent && !lastHitAgent.invertX) // agent A hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent B hits into wall
                        {
                            AgentAWins();
                        }
                    }
                    // Agent A hits long
                    else // if (lastAgentHit == AgentRole.A)
                    {
                        AgentBWins();
                    }
                    Reset();
                }
                else if (collision.gameObject.name == "floorA")
                {
                    // Agent A hits into floor, double bounce or service
                    if (lastFloorHit == FloorHit.FloorAHit    // double bounce
                        // || lastFloorHit == FloorHit.Service
                        )
                    {
                        if (lastHitAgent && lastHitAgent.invertX) // agent B hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent A hits into floor
                        {
                            AgentBWins();
                        }
                        Reset();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorAHit;
                    }
                }
                else if (collision.gameObject.name == "floorB")
                {
                    // Agent B hits into floor, double bounce or service
                    if (lastFloorHit == FloorHit.FloorBHit
                        // || lastFloorHit == FloorHit.Service
                        )
                    {
                        if (lastHitAgent && !lastHitAgent.invertX) // agent A hit a winner
                        {
                            lastHitAgent.Wins();
                        }
                        else                      // Agent B hits into floor
                        {
                            AgentAWins();
                        }
                        Reset();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorBHit;
                    }
                }
                else if (collision.gameObject.name == "net")
                {
                    if (lastHitAgent && !lastHitAgent.invertX)
                    {
                        AgentBWins();
                    }
                    else // if (lastAgentHit == AgentRole.B)
                    {
                        AgentAWins();
                    }
                }
            }
            else if (collision.gameObject.CompareTag("agent"))
            {
                var agent = collision.gameObject.GetComponent <TennisAgentA>();
                agent.AddReward(0.6f);
                ++agent.hitCount;
                if (!agent.invertX) // A
                {
                    // Agent A double hit
                    if (lastHitAgent && !lastHitAgent.invertX)
                    {
                        AgentBWins();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorHitUnset;
                    }
                }
                else // if (collision.gameObject.name == "AgentB")
                {
                    // Agent B double hit
                    if (lastHitAgent && lastHitAgent.invertX)
                    {
                        AgentAWins();
                    }
                    else
                    {
                        lastFloorHit = FloorHit.FloorHitUnset;
                    }
                }
                lastHitAgent = agent;
            }
        }