- Home /
Pac-Man Ghost AI
i tried to make a animation for the ghost ai and tried to stop the animation and make it look at the player but i got to stuck but i tried to go with raycasting which ended up with the same result but with errors heres what i had using UnityEngine; using System.Collections; public class ghostAI : MonoBehaviour { %|-1137081967_1|% %|-1863972952_2|% %|1266049162_3|% %|1716386108_4|% %|-415999389_5|% %|149016438_6|% %|-1650711200_7|% %|-235674992_8|% %|-1548164085_9|% %|1802277094_10|% %|1778270671_11|% %|1741920446_12|% %|-4946239_13|% %|-2096908437_14|% } but i got a few errors on line (17, 15, 9) and i cannot resolve it i want the ghost to move but not touch the walls and not get stuck
When a ghost touches a wall it rotates when it does not touch a wall it moves forward but i want a full snaped turn not a 0.1 turn
sorry about the code heres it here in text form using UnityEngine; using System.Collections;
public class ghostAI : $$anonymous$$onoBehaviour {
public int speed;
void Update(){
RaycastHit hit;
Ray ray = Vector3.forward;
if (Physics.Raycast (ray, out hit)) {
if (hit.collider != null) {
transform.Rotate (transform.forward * speed * Time.deltaTime);
}
if (Physics.Raycast(transform.position, ray, 10) == null) {
print ("Empty Spot $$anonymous$$oving Forward");
transform.translate (transform.forward * Time.deltaTime * speed);
}
}
}
}
Your answer