Hi folk,
I’m trying to use linecast to detect interference between player and enemy in a 2d platformer game.
when I put the enemy in a specific layer to be used in linecast detection, the enemy starts moving constantly without any script, input from my end. Everything works just fine except that the enemy moving at its own when I assign it to a layer.
here is my code:
void detectEnemy()
{
myDetector = Physics2D.Linecast(startPoint.position, endPoint.position,
LayerMask.GetMask(“Enemy Layer”));
Debug.DrawLine(startPoint.position, endPoint.position);
if (myDetector)
{
Debug.Log("Enemy Detedted as: " + myDetector.collider.name);
}
}