Hey, I have a basic enemy that patrols between two or more points, my game is a side scroller and Id like not to be able to push him forward/backward on the Z axis, causing him to fall off the platform. heres the part of the script that controls patrolling;
if( grounded )
{
if(CurrentWayPoint < WayPoint.length)
{
var target : Vector2 = WayPoint[CurrentWayPoint].position;
var moveDirection : Vector2 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
CurrentWayPoint++;
}
else
{
velocity = moveDirection.normalized * Speed;
}
}
else
{
if( loop )
{
CurrentWayPoint = 0;
}
else
{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
}
this is in the Update function and 'grounded' is if it is falling or not. How and where would I put something like `transform.position.z = 0;` ???