So, I’m making a AI system in my game and I’m working on melee attacks for the AI.
The raycast is being “casted” properly, but it only detects hits if the objects it’s attached to is standing still.
Which it’s not since the AI follows the player.
Pretty much raycasting is not possible if the gameObject it’s attached to is moving?
Or is there any fix for this? Maybe the only fix is to change to Box Colliders or Rigid ones instead?
Thanks. ![]()
Almost forgot the code which is here : (but I’m 99% sure this isn’t the problem)
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(gameObject.transform.position, fwd, out hit, attackRange))
{
Debug.Log("AI Attack raycast is hitting SOMETHING");
if (hit.transform.gameObject.tag == "Player" && canAttack)
{
Debug.Log("Enemy raycast is hitting the PLAYER!");
hit.transform.SendMessage("Damage", 25);
}
}
Debug.DrawLine(transform.position, fwd, Color.green);