My player
object containing a rigidbody
that is controlled using Input
, is not colliding with an enemy
unless keys are pressed. When no keys
are pressed, the enemy
simply goes through the player
without collision
. I'm using Unity 5.6.1f1.
I figured the problem is in the Patrol
class because when I don't attach the script to the enemy
object the collision
appears to take place fine.
But I don't know what I'm doing wrong in this script because I seems to do it's task well. I wrote this script to make the enemy
object move between points in patrolPoints
which are just some empty
's in the game world.
So, I would like to know if I'm doing it right or is there another way to do it.
Patrol.cs
public class Patrol : MonoBehaviour {
public Transform[] patrolPoints;
public float speed;
private int currentPoint;
private bool forward;
// Use this for initialization
void Start () {
transform.position = patrolPoints [0].position;
currentPoint = 0;
forward = true;
}
// Update is called once per frame
void Update () {
if (transform.position == patrolPoints [currentPoint].position) {
if (currentPoint < patrolPoints.Length - 1 && forward) {
currentPoint++;
} else {
currentPoint--;
forward = false;
}
if (currentPoint == 0)
forward = true;
}
transform.position = Vector3.MoveTowards (transform.position,
patrolPoints [currentPoint].position, speed * Time.deltaTime);
}
}
Input
settings.... \$\endgroup\$