hello,
I'm trying to move the enemies move randomly until they touch the wall and then again with random directions.
this is the script that i used for the random direction
public float speed = 5.0f;
public Vector3 direction;
void Start()
{
direction = (new Vector3(Random.Range(-1.0f,1.0f), Random.Range(-1.0f,1.0f),0.0f)).normalized;
transform.Rotate(direction);
}
void Update()
{
transform.position += direction * speed * Time.deltaTime;
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.tag == "Muri")
{
random ();
}
}
void random ()
{
Vector3 direction = (new Vector3(Random.Range(-1.0f,1.0f), Random.Range(-1.0f,1.0f),0.0f)).normalized;
transform.Rotate(direction);
}
should be doing movements similar to the [wandered][1] of geometry wars and sometimes it works but many times when it touches the wall continues to move in that direction and I can not understand why, I made you a picture to make you understand what succedde sometimes when touching the wall.
![alt text][2]
this is as it should be, and in fact every now and then it works but not always.
![alt text][3]
Thanks in advance!
[1]: http://wikicheats.gametrailers.com/Geometry_Wars_2_-_XBLA/Enemy_Types
[2]: /storage/temp/26886-enemy+movement.png
[3]: /storage/temp/26887-how+should+be.png
↧