Hi, I am trying to get my ray cast to shoot from the player to where the mouse is clicked. I thought I had it set up correctly, but while testing I noticed the raycast is always going in the same direction, even when the player moves. I do not have a lot of experience with raycasts, so im not exactly sure where I am going wrong with this, If anyone could possibly help with what the issue is, it would be greatly appreciated.
RaycastHit ShootHit;
Ray PlayerToMouse = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(PlayerToMouse, out ShootHit, PlayerMouseDistance, ShootableMask))
{
EnemyHealth enemyHealth = ShootHit.collider.GetComponent<EnemyHealth>();
if (enemyHealth != null)
{
enemyHealth.TakeDamage(DamagePerShot, ShootHit.point);
}
}
EDIT: OK, I figured out my issue. The raycast is fine, its the drawing of the raycast the was the issue. In this case how would I draw the ray. The only way I have done it before is
Debug.DrawRay(transform.position, transform.forward * PlayerMouseDistance);
Which would not work for this situation obviously