Quantcast
Viewing all articles
Browse latest Browse all 1488

Can someone help me to understand why this raycast is not working properly?

![alt text][1] [1]: /storage/temp/182650-screenshot-2021-06-26-194508.png RaycastHit hit; var rayDirection = Player.transform.position - Enemy.transform.position; Debug.DrawRay(transform.position, rayDirection); if (Physics.Raycast(transform.position, rayDirection, out hit)) { if (hit.collider.gameObject.tag == "Player"){ Debug.Log("Works"); } else { } } This code is inside of the update function. Basically, the ray is drawn in the right position, but the Debug.Log("Works"); is never printed into the console. I am trying to make this so the enemy will only shoot at the player when they are in direct line of sight. Thanks for the help!

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>