void FixedUpdate() { Vector3 fwd = transform.TransformDirection(Vector3.forward); Physics.Raycast(transform.position, fwd, out hit, 5); FPSAI controller = this.GetComponent <FPSAI>(); if (Physics.Raycast(transform.position, fwd, 5) && rotating == false) { if (hit.transform.CompareTag("Wall")) { ; } { rotating = true; //controller.inputX = -controller.inputX; //controller.inputY = -controller.inputY; storedWalkSpeed = controller.walkSpeed; controller.walkSpeed = 0.0f; // Vector3 targetRotate = (0, 180, 0); // this.transform.Rotate(0, 180, 0); //this.transform.Rotate(Vector3.left, ); print("There is something in front of the object!"); } } if (rotating == true) { rotation = rotateSpeed * Time.deltaTime; rotateCurrent = rotateCurrent + rotation; // this.transform.Rotate(0, rotation, 0); //this.transform.Rotate(Vector3.left, ); //controller.walkSpeed = 0.0f; // print("There is something in front of the object!"); if (rotateCurrent >= rotateMax) { // update the rotation, we probably want slightly less float new_rotation = rotation - (rotateCurrent - rotateMax); this.transform.Rotate(0, new_rotation, 0); rotating = false; controller.walkSpeed = storedWalkSpeed; rotateCurrent = 0.0000f; } if (rotating == true) { this.transform.Rotate(0, rotation, 0); } } }
void Update() { Vector3 fwd = transform.TransformDirection(Vector3.forward); Physics.Raycast(transform.position, fwd, out hit, maxDistance); FPSAI controller = this.GetComponent <FPSAI>(); if (Physics.Raycast(transform.position, fwd, maxDistance) && rotating == true) { print(hit.transform.tag); if (hit.transform.CompareTag("Player")) { rotating = false; controller.walkSpeed = chargeSpeed; storedWalkSpeed = controller.walkSpeed; } } if (rotating == true) { rotation = rotateSpeed * Time.deltaTime; this.transform.Rotate(0, rotation, 0); controller.walkSpeed = 0.0f; storedWalkSpeed = controller.walkSpeed; } if (rotating == false) { chargeDistance = chargeDistance + (storedWalkSpeed * Time.deltaTime); if (chargeDistance >= chargeDistanceMax) { rotating = true; chargeDistance = 0.0f; storedWalkSpeed = 0.0f; controller.walkSpeed = storedWalkSpeed; } } }
// Update is called once per frame void Update() { bool transform = Input.GetButtonDown("Transform"); bool capture = Input.GetButtonDown("Capture"); if (transform ^ capture) { Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { FPSAI fsapi = hit.transform.root.GetComponent <FPSAI>(); if (fsapi == null) { return; } GameObject gameObject = fsapi.gameObject; if (string.IsNullOrEmpty(gameObject.tag) || !gameObject.tag.EndsWith("Enemy", System.StringComparison.InvariantCultureIgnoreCase)) { return; } if (transform && !string.IsNullOrEmpty(CurrentTag) && CurrentTag != gameObject.tag) { gameObject.tag = CurrentTag; CurrentTag = string.Empty; } else if (capture && !string.IsNullOrEmpty(gameObject.tag)) { CurrentTag = gameObject.tag; } } } }
void FixedUpdate() { FPSAI controller = this.GetComponent <FPSAI>(); RedWalkerAI red_walk_ai = GetComponent <RedWalkerAI>(); BlueWalkerAI blue_walk_ai = GetComponent <BlueWalkerAI>(); GreenWalkerAI green_walk_ai = GetComponent <GreenWalkerAI>(); YellowWalkerAI yellow_walk_ai = GetComponent <YellowWalkerAI>(); red_walker = gameObject.transform.Find("RedWalker").gameObject; blue_walker = gameObject.transform.Find("BlueWalker").gameObject; green_walker = gameObject.transform.Find("GreenWalker").gameObject; yellow_walker = gameObject.transform.Find("YellowWalker").gameObject; if (gameObject.tag == "RedEnemy") { controller.walkSpeed = 6.0f; blue_walk_ai.enabled = false; red_walk_ai.enabled = true; green_walk_ai.enabled = false; yellow_walk_ai.enabled = false; red_walker.SetActive(true); blue_walker.SetActive(false); green_walker.SetActive(false); yellow_walker.SetActive(false); } if (gameObject.tag == "BlueEnemy") { controller.walkSpeed = 6.0f; blue_walk_ai.enabled = true; red_walk_ai.enabled = false; green_walk_ai.enabled = false; yellow_walk_ai.enabled = false; red_walker.SetActive(false); blue_walker.SetActive(true); green_walker.SetActive(false); yellow_walker.SetActive(false); } if (gameObject.tag == "GreenEnemy") { blue_walk_ai.enabled = false; red_walk_ai.enabled = false; green_walk_ai.enabled = true; yellow_walk_ai.enabled = false; red_walker.SetActive(false); blue_walker.SetActive(false); green_walker.SetActive(true); yellow_walker.SetActive(false); } if (gameObject.tag == "YellowEnemy") { blue_walk_ai.enabled = false; red_walk_ai.enabled = false; green_walk_ai.enabled = false; yellow_walk_ai.enabled = true; red_walker.SetActive(false); blue_walker.SetActive(false); green_walker.SetActive(false); yellow_walker.SetActive(true); } }
void FixedUpdate() { FPSAI controller = this.GetComponent <FPSAI>(); controller.walkSpeed = 0.0f; }