How to make an object used for enemy sight shorter, when enemy is looking at a wall?

jakaloy

Member
I'm making a top down shooter and for enemy sight I made an object in a shape of what I want for enemy to be able to see. Basicly I have a weird triangle shaped object on top of an enemy, with a tip on his head. It works like you can expect, when the player collides with this object the enemy starts attacking. But the problem is that, if the enemy is facing a wall, the object will go through a wall and if the player collides with it, the enemy will still attack, even though he shouldn't be able to see him. How can I cut or deactivate the part of the object, that would look through a wall? Or is there a better easier way to make an enemy see using collision_line or even raycasting?
 

CloseRange

Member
cutting off the object can't really be done in a clean and easy way. Yes collision_line is exactly what you'd want.
Right before he attacks just do :

Code:
if( !collision_line(x, y, obj_player.x, obj_player.y, obj_wall, false, false) ) {
    // ok, now attack
}
 
Top