Beispiel #1
0
    void Start() //reset vals
    {
        lastPlayerWithBall = null;
        PlayerWithBall     = null;
        GameObject environment = gameObject.transform.parent.gameObject;

        ball.transform.localPosition = new Vector3(0, 5, 0);
        ballRgd = ball.GetComponent <Rigidbody>();
        ballRgd.angularVelocity = Vector3.zero;
        ballRgd.velocity        = Vector3.zero;
    }
Beispiel #2
0
 public void outOfBounds()//reset the enviroment if ball is out of bounds
 {
     ball.transform.localPosition = new Vector3(0, 5, 0);
     ballRgd.angularVelocity      = Vector3.zero;
     ballRgd.velocity             = Vector3.zero;
     if (PlayerWithBall != null)
     {
         PlayerWithBall.GetComponent <Full_train_nn>().hasBall = false;
     }
     PlayerWithBall     = null;
     lastPlayerWithBall = null;
 }
Beispiel #3
0
    public void changePlayerWithBall(Full_train_nn withBall)         // called by a player when he took over a ball
    {
        if (PlayerWithBall && PlayerWithBall != withBall.gameObject) //minus reward if stolen
        {
            PlayerWithBall.GetComponent <Full_train_nn>().timer   = 1f;
            PlayerWithBall.GetComponent <Full_train_nn>().hasBall = false;
            PlayerWithBall.GetComponent <Full_train_nn>().AddReward(-0.1f);
        }

        /*if (lastPlayerWithBall != null && lastPlayerWithBall.team == withBall.team && lastPlayerWithBall != withBall && PlayerWithBall == null)//pass acured
         * {
         *  withBall.AddReward(0.05f);
         *  lastPlayerWithBall.AddReward(0.05f);
         * }
         * else if(lastPlayerWithBall != null && lastPlayerWithBall.team != withBall.team)//block
         * {
         *  withBall.AddReward(0.05f);
         *  lastPlayerWithBall.AddReward(-0.05f);
         * }*/
        PlayerWithBall = withBall.gameObject;
        //add reward if was blocked
        if ((lastPlayerWithBall != null && !lastPlayerWithBall.Equals(withBall) && lastPlayerWithBall.team != withBall.team) || lastPlayerWithBall == null)
        {
            /*if (lastPlayerWithBall)
             *  lastPlayerWithBall.AddReward(-0.1f);
             * withBall.AddReward(0.1f);*/
        }

        lastPlayerWithBall = withBall;

        /*foreach (var ps in playerConfigs)
         * {
         *  if (ps.agentScript.team == PlayerWithBall.GetComponent<Full_train_nn>().team)
         *  {
         *      ps.agentScript.jumpHeight = ps.agentScript.lowJumpHeight;
         *  }
         *  else
         *  {
         *      ps.agentScript.jumpHeight = ps.agentScript.highJumpHeight;
         *  }
         * }*/
    }
Beispiel #4
0
 // Update is called once per frame
 void Update()
 {
     if (ball.transform.localPosition.y <= 1 && lastPlayerWithBall != null)
     {
         lastPlayerWithBall.AddReward(-0.1f);
         lastPlayerWithBall = null;
     }
     if (ball.transform.localPosition.z > 12 || ball.transform.localPosition.z < -12) //check if the ball is out of bounds
     {
         outOfBounds();
     }
     if (ball.transform.localPosition.y >= 25 || ball.transform.localPosition.y <= -2)
     {
         outOfBounds();
     }
     if (ball.transform.localPosition.x > 33 || ball.transform.localPosition.x < -33)
     {
         outOfBounds();
     }
 }
Beispiel #5
0
 public void PlayerLeftBall(Full_train_nn player)//update player with ball value when a player leaves the ball
 {
     PlayerWithBall = null;
 }