void FixedUpdate() { timer -= Time.deltaTime; if (hasBall)//update ball values { ball.transform.localPosition = new Vector3(transform.localPosition.x + right * 1.1f, transform.localPosition.y + 0.75f, transform.localPosition.z); ballRgd.angularVelocity = Vector3.zero; ballRgd.velocity = Vector3.zero; } //move funcs if (Input.GetKey(KeyCode.RightArrow) && right == 1) { transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.LeftArrow) && right == 1) { transform.Translate(new Vector3(-1, 0, 0) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.UpArrow) && right == 1) { transform.Translate(new Vector3(0, 0, 1) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.DownArrow) && right == 1) { transform.Translate(new Vector3(0, 0, -1) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.K) && right == -1) { transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.H) && right == -1) { transform.Translate(new Vector3(-1, 0, 0) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.U) && right == -1) { transform.Translate(new Vector3(0, 0, 1) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.J) && right == -1) { transform.Translate(new Vector3(0, 0, -1) * Time.deltaTime * agentSpeed); } if (Input.GetKey(KeyCode.Space)) { jump(); } if (Input.GetKey(KeyCode.S) && hasBall) { shooting.shoot(); timer = 1f; } if (Input.GetKey(KeyCode.A) && hasBall) { passing.pass(passing.teammate); timer = 1f; } }
void Update() { if (ballTouch == 0 && flag == false) { Debug.Log("Ball touch is 0 "); flag = true; } timer -= Time.deltaTime; if (hasBall) //update ball vals if has ball { ball.transform.localPosition = transform.localPosition + Vector3.up * 2.5f; //transform.forward * 1.7f + Vector3.up * 1.3f; ballRgd.angularVelocity = Vector3.zero; ballRgd.velocity = Vector3.zero; if (actionMaker == 1)//if wants to shoot shoot { hasBall = false; actionMaker = 0; shooting.shoot(); actionMaker = 0; timer = 1f; } if (actionMaker == 2)//if want to pass pass { hasBall = false; actionMaker = 0; passing.pass(teamate1); actionMaker = 0; timer = 1f; } /*if (actionMaker == 3)//jump * { * hasBall = false; * passing.pass(teamate2); * actionMaker = 0; * timer = 1f; * }*/ } else { actionMaker = 0; } //check if out of bounds if true reset and punish if (transform.localPosition.z > 12 || transform.localPosition.z < -12) { AddReward(-0.05f); transform.localPosition = startingLoc; } if (transform.localPosition.y >= 25 || transform.localPosition.y <= -2) { AddReward(-0.05f); transform.localPosition = startingLoc; } if (transform.localPosition.x > 33 || transform.localPosition.x < -33) { AddReward(-0.05f); transform.localPosition = startingLoc; } }