Raycast not detecting "hits" if the raycast position is being transformed?
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);
Answer by ShroomWasTaken · Sep 01, 2015 at 05:11 PM
Solved it, raycasting decided to suddenly start to work again..... o.o
Your answer
Follow this Question
Related Questions
Raycast doesn't stay in one place 0 Answers
Physics Raycast not working 1 Answer
raycasthit to set new move location 0 Answers
About AI detecting a sound 1 Answer
Use raycast to change color 1 Answer