- Home /
Grid Pathfinding
Hey there guys, Im making a game where an enemy moves around on a 5 x 5 tile grid, In this game the tiles can be deleted. My problem is that I am trying to use ray casting for the player to see if there is walkable tiles around the player. Once I find those tiles I want the player to chose a path to move. My Code:
IEnumerator FindPad()
{
Vector3 BackDir = new Vector3 (-5f, 0, 0);
Vector3 WestDir = new Vector3 (0, 0, -5f);
Vector3 EastDir = new Vector3 (0, 0, 5f);
Vector3 FrontDir = new Vector3 (5f, 0, 0);
Vector3 BackLeftDir = new Vector3 (-5f, 0, -5f);
Vector3 BackRightDir = new Vector3 (-5f, 0, 5f);
Vector3 FrontLeftDir = new Vector3 (5f, 0, -5f);
Vector3 FrontRightDir = new Vector3 (5f, 0, 5f);
if (!standing) {
if (Back.GetComponent<EnemyAreaDetectionBack> ().moveBack == true) {
Enemy.GetComponent<GridMovement> ().pos += BackDir;
}
else if (West.GetComponent<EnemyAreaDetectionWest> ().moveWest == true) {
Enemy.GetComponent<GridMovement> ().pos += WestDir;
}
else if (East.GetComponent<EnemyAreaDetectionEast> ().moveEast == true) {
Enemy.GetComponent<GridMovement> ().pos += EastDir;
}
else if (Front.GetComponent<EnemyAreaDetectionFront> ().moveUp == true) {
Enemy.GetComponent<GridMovement> ().pos += FrontDir;
}
else if (BackLeft.GetComponent<EnemyAreaDetectionBackLeft> ().moveBackLeft == true) {
Enemy.GetComponent<GridMovement> ().pos += BackLeftDir;
}
else if (BackRight.GetComponent<EnemyAreaDetectionBackRight> ().moveBackRight == true) {
Enemy.GetComponent<GridMovement> ().pos += BackRightDir;
}
else if (FrontLeft.GetComponent<EnemyAreaDetectionFrontLeft> ().moveFrontLeft == true) {
Enemy.GetComponent<GridMovement> ().pos += FrontLeftDir;
}
else if (FrontRight.GetComponent<EnemyAreaDetectionFrontRight> ().moveFrontRight == true) {
Enemy.GetComponent<GridMovement> ().pos += FrontRightDir;
}
}
else if (standing) {
yield return new WaitForSeconds (0.1f);
StartCoroutine(FindPad());
}
}
When the tile underneath the player is deleated the player moves back but when the tile under the player AND the one behind the player is deleated, he just falls.
If this post needs clarification please tell me because im stuck :P
Thanks, Brandon
Your answer
Follow this Question
Related Questions
How do I change movement speed of my Raycasting A*pathfinding transform? 2 Answers
(A* Pathfinding) Enemy is moving step by step when near player 3 Answers
What Is The Best AI Solution For A Restaurant Style Strategy Game? 0 Answers
How do I handle Pathfinding in Shoot Em Ups? 1 Answer
Alternative to remainingDistance (Entire Path Calculation)? 0 Answers