Hi I need some outside help with this problem I am having. Can’t see what could be going wrong. Hoping someone else might be able to.
I am making a state AI for my enemy based on way points. There are three states: IDLE, ATTACKING, PURSUING.
When IDLE the enemy just follows the way points and checks for attack conditions. An enemy is IDLE when the player is not in range. The enemy will attack when the player is in range AND the enemy has direct line of sight.
When ATTACKING the enemy moves towards the target (player) and constantly checks to make sure they are still in line of sight (LOS). If the enemy loses LOS then its state changes to PURSUING.
When PURSUING the enemy picks the closest way point to both the enemy and the target that also has LOS to both the enemy and the target. If there is ever a time in which a waypoint with these properties can’t be found then the enemy gives up persuit and returns to IDLE. Otherwise if while PURSUING the enemy regains LOS they return to ATTACKING.
My problem at the moment is the condition to go from IDLE to ATTACKING. For some reason it knows when the target is in range but ignores part of the if statement below regarding LOS.
else if (eState == EnemyState.IDLE)
{
if (Vector3.Distance(target.transform.position, transform.position) < attackRange && !Physics.Raycast(transform.position, target.position))
eState = EnemyState.ATTACKING;
}
It seems that the raycast is returning false even when there is defiantly an intersecting wall. See the linked screenshot (hopefully you can make it out). What it should do is continue moving round the way points until it does have LOS.
Screenshot: http://i981.photobucket.com/albums/ae300/martianxx/Example_zps91c48b70.png
Thanks.
I have figured it out, for some reason ray casts through my walls don't register collision, they do have a box collider though. They are just scaled cube game objects. Edit: In case you wandered they are not set to be a trigger
– dfghdh