This was my first time using the Raycast stuff, and I had it working for the past 3 days, but now it just does not show the enemies, yet I changed nothing. Before it stopped working, this is what it did.
It would only show the enemy if they were in collision with my vision cone and there was no wall in the way; otherwise, they would not show. Now they just don’t show at all when in the vision cone
Maybe there is also a better, cleaner way to get this to work? I just wish i knew how i broke it, has stumped me for hours
You’ve got an unconditional hide enemy action in the top event of that screen shot.
Also, there’s no need for that second raycast. If the enemy is not in collision with the player_vision, shouldn’t they be hidden anyway?
And a tip - too many of the
repeat for each object events can slow the game down, so don’t use the
repeat for each enemy if it’s not necessary.
For the first repeat for each instance of enemy, check for enemy collision and visibility first and have the repeat for all enemy as a subevent off that. It will mean you are iterating over fewer enemies - only those ones that are in collision:
And you can do away with the second
repeat for all enemy and make it much more efficient with one event that checks if the enemy is visible and player_vision is not in collision with enemy:
I had the 2nd one because otherwise you would see enemys on the other side of the wall if the player_vision makes collision with them. I tried what you posted above but now its the opposite problem, I see the enemys all the time.
If I use this it works as should but the wrong way round ( i see enemy’s on the other side of walls but not when in same room as them) works this way because its inverted right, but if i remove the inversion so it works the correct way then the enemys are just visible all the time again
Sorry, that’s my mistake. That second condition should be inverted. i.e. the events is actioned if the enemy is visible but no longer in the player’s vision
A raycast fires a ray from one position to another, and checks it it hits the objects it’s checking against.
So your raycast is cast from the enemy to the player, and is successful if it hits a wall object.
But I don’t understand your logic there - it reads
if the enemy is not in collision with player_vision, then do a raycast to them.
Shouldn’t that first event be normal (enemy collides with player_vision), and not inverted, and the action to hide them?
Yeah i worked that last bit out but i was still confused so i deleted it all to start from scratch and got it working by just doing this
no idea why i did not write it like that the first time tbh I just confused myself 3days ago thinking i needed two raycasts. Thanks for the help MrMen