Question by
Meltdragon · Jul 02, 2020 at 10:24 AM ·
2draycastraycasthit2dtop down shooter
Raycast2D don't hit anything below
I have a problem with the Raycast. Our enemy uses a raycast2D to see if the player is behind something or not but it seems that he only cast above him and not below so if the player stands right below him the enemy doesn't shoot anymore.
Vector2 direction = PlayerHandler.Player.transform.position - enemy.transform.position;
RaycastHit2D hit = Physics2D.Raycast(enemy.transform.position, direction, Vector2.Distance(PlayerHandler.Player.transform.position, enemy.transform.position) , ~enemy.Layermask);
timer.Tick();
if (timer.CurrentTime <= 0)
{
if (hit.collider != null)
{
Debug.LogError("HIT ME");
if (hit.collider.gameObject.CompareTag("Player"))
{
Shoot();
timer.ResetTime();
}
}
}
}
it is in the update function
Comment
Your answer
Follow this Question
Related Questions
Making a GameObject follow the direction of a RayCast 1 Answer
Rigidbody blocking raycasts 2D 0 Answers
Select from multiple character to move 0 Answers
2D raycast not working 0 Answers
Raycast not detecting bullet 0 Answers