//halt function if AI has to stop void Idle() { if (Vector3.SqrMagnitude(originPoint - tankTransform_.position) > (howClose * howClose)) { if (tankTransform_.position != originPoint) //if AI ISN'T at original positioning move there before anything else { if (sensing.CanSee(GameManagement.instance.player1) || sensing.CanHear(GameManagement.instance.player1)) { return; } else { AITurned(originPoint, tankInfo_.turnSpeed); motor_.Movement(tankInfo_.moveForwardSpeed); } } else { //do nothing once back at origin point } } else { //do nothing if close enough to origin point } }
// Update is called once per frame void FixedUpdate() { if (Input.GetKey(KeyCode.W)) { motor.Movement(speedInfo.moveForwardSpeed); //forward movement at normal speed if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2"))) { noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, moveVolume); } } else if (Input.GetKey(KeyCode.S)) { motor.Movement(-speedInfo.moveBackSpeed); //allows backward movement for slower speed if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2"))) { noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, moveVolume); } } if (Input.GetKey(KeyCode.D)) { motor.Rotation(speedInfo.turnSpeed); //turn clockwise if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2"))) { noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, turnVolume); } } else if (Input.GetKey(KeyCode.A)) { motor.Rotation(-speedInfo.turnSpeed); //turn counterclockwise if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2"))) { noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, turnVolume); } } if (Input.GetKeyDown(KeyCode.Space) && !hasFired && timeBetweenFire >= fireTimer) //fires a shell { GameObject ammoClone = Instantiate(ammunition, gameObject.GetComponent <TankData>().FirePoint.position, transform.rotation); if (gameObject.tag == "Player1") { ammoClone.tag = "Player1Shell"; ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue; } if (gameObject.tag == "Player2") { ammoClone.tag = "Player2Shell"; ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue; } StartCoroutine("TimeUp"); hasFired = true; } else if (hasFired && timeBetweenFire <= fireTimer) { StopCoroutine("TimeUp"); fireTimer = 0; hasFired = false; } /*if (player.tag == ("Player1")) * { * * } * for future milestones * else if (player.tag == ("Player2")) * { * * }*/ }
// Update is called once per frame void FixedUpdate() { if (Input.GetKey(KeyCode.W)) { motor.Movement(speedInfo.moveForwardSpeed); //forward movement at normal speed } else if (Input.GetKey(KeyCode.S)) { motor.Movement(-speedInfo.moveBackSpeed); //allows backward movement for slower speed } if (Input.GetKey(KeyCode.D)) { motor.Rotation(speedInfo.turnSpeed); //turn clockwise } else if (Input.GetKey(KeyCode.A)) { motor.Rotation(-speedInfo.turnSpeed); //turn counterclockwise } if (Input.GetKeyDown(KeyCode.Space) && !hasFired && timeBetweenFire >= fireTimer) //fires a shell { GameObject ammoClone = Instantiate(ammunition, gameObject.GetComponent <TankData>().FirePoint.position, transform.rotation); //Object.Instantiate<GameObject>(ammunition); //just this doesn't work at all either (mainly because I'm using a prefab that isn't in the world at all) //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.position, transform.rotation, // gameObject.GetComponent<TankData>().FirePoint.parent); //this works HOWEVER any movement of my tank afterwards moves the shell as well //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.parent); //this works as well HOWEVER any movement of my tank afterwards moves the shell as well //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.parent, true); //this does NOT work for some reason //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.position, transform.rotation); //this creates the object at position but does not set as child //ammunition.transform.SetParent(gameObject.GetComponent<TankData>().FirePoint, true); //this won't work and i can't figure out HOW to make it work if (gameObject.tag == "Player1") { ammoClone.tag = "Player1"; ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue; } if (gameObject.tag == "Player2") { ammoClone.tag = "Player2"; ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue; } StartCoroutine("TimeUp"); hasFired = true; } else if (hasFired && timeBetweenFire <= fireTimer) { StopCoroutine("TimeUp"); fireTimer = 0; hasFired = false; } if (player.tag == ("Player1")) { } /* for future milestones * else if (player.tag == ("Player2")) * { * * }*/ }
// Update is called once per frame void Update() { motor.Movement(speedInfo.moveForwardSpeed); motor.Rotation(speedInfo.turnSpeed); }