Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Simple AI Roaming Script Help C#

$
0
0
I want to code to make an enemy move in a random direction every so often, so i have created a random number generator system where depending what number is called it moves in a different location, however it doesn't seem to work and will either not work at all or will not stop moving; It is for a top down 2D shooter. Code: { public float moveSpeed; public float moveChance; public float moveTime; public bool IsRoaming; public bool IsRoamingUp; public bool IsRoamingLeft; void FixedUpdate () { Roaming (); RoamMoveUp (); } void Roaming () { if ((moveChance == 0)) { moveChance = Random.Range(0, 0); } if ((moveChance == 1)) { IsRoamingUp = true; } } void RoamMoveUp () { if (IsRoamingUp = true) { moveTime++; transform.position += Vector3.up * moveSpeed; if (moveTime > 10) { Debug.Log("ItsWorking!"); moveChance = Random.Range (0, 0); IsRoamingUp = false; moveTime = 0; } } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>