# Raycast does not go to target position

There is a part in my script where I need to make a raycast check from my gun's muzzle to the enemy. This enemy could be anywhere around player.

I found my ray is not connecting to the target position!

public Transform target, Bullet_position;

void Update {

if (target != null)
{
RaycastHit hit;
if (Physics.Raycast(Bullet_position.position, target.position, out hit, 500)
{
Debug.DrawRay(Bullet_position.position, target.position, Color.blue, 500);

if (hit.collider.tag == "enemy")
{
print(" In range and I can see you! ");
}
else
{
print(" None! ");
}
}
}
} // end update.

• You know the second argument is a direction, not a position, right? Did you mean to use a linecast? Dec 30 '18 at 22:20
• Yes, linecast is what I need for this script. Thank you DMG.
– Omer
Dec 31 '18 at 7:28
• Note also that you should use the CompareTag() method instead of .tag == Dec 31 '18 at 15:42

if (Physics.Raycast(Bullet_position.position, target.position, out hit, 500))
Debug.DrawRay(Bullet_position.position, target.position, Color.blue, 500);
Bullet_position.position
Bullet_position.position + target.position