# Why does collision only work when keys are being pressed?

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);
}
}

• I've used the default Input settings.... – Anish Silwal May 31 '17 at 13:03
• @Gnemlock I've added my codes.. – Anish Silwal May 31 '17 at 13:11
• You're sure you have no other behaviours running that might read keyboard? – Engineer May 31 '17 at 13:16
• The fact that we are having to enter into discussion like this points to why we require a minimal, verifiable example of the problem to consider debugging questions ontopic. – Gnemlock May 31 '17 at 13:37
• @Gnemlock While you are correct in saying so, one must try to appreciate that users who come here with Unity problems cannot always provide all the information till they are asked for it... heck, it's hard even for users writing applications that are fully represented as text. Let alone where a lot of the data is by default stored as part of the project metadata. – Engineer May 31 '17 at 13:44

transform.position = Vector3.MoveTowards (transform.position, patrolPoints [currentPoint].position, speed * Time.deltaTime);