Hi I was having some problem with my enemy Ai code where the enemy would turn a random direction. Now because I do not want to turn the actual object and just want it to move in that angle I having a litte difficulty with the math. Here is the code:
if( counter <= 0)
{
counter = 1;
dir = Mathf.Deg2Rad*Random.Range(0,360);
}
else
counter -= Time.deltaTime;
//moves the object in the x and z direction
amountToMove.x = Mathf.Sin(dir)*spd*Time.deltaTime;
amountToMove.z = Mathf.Cos(dir)*spd*Time.deltaTime;
Now part of the reason that I’m having difficulty is because I am not sure what direction the object should be moving so it is hard to tell if it is actually moving in the right direction.