I have a question about enemy behavior in a topdown game. The goal is: if the player is in the viewport of the monster (so the player is close to the monster + there are no walls/obstacles between them), the monster should follow to player. I tried to do this with rayracing, and it kind of worked.
The issue is: Not all monster instances behave independently. Only one instance reacts if the player is in sight and the other instances follow that one «mother» monster.
With your code, i think the enemy could shoot a invisible bullet in one direction, if the bullet collides with the player it moves the enemy in the direction of the player and delete the bullet, if it collides with a wall it delete the bullet.
Can raycast work like a cone? start from where object is and spawn until the max distance.
I have been working with invisible sprites that works like hitbox, attached to some point of an enemy and simulate a frontal visual, so if you are behind of enemy, it cant see you.
Can raycast do that? to avoid some lines on my actions
As Reborn mentioned you need several raycasts for the outline of the cone and the area inside. I read somewhere that a lot of raycasts can be potentially problematic for the performance. Using an invisible sprite for simulating the field of view is often the easier and better method.
Yes basically like that, but the angles of that picture are not quite accurate (in that case it would be
top-front: [ between -45 and -30 ],
front: [ 0 ],
bottom-front: [between 45 and 30 ]
You can use pre-determinated angles for a platformer game but if it is a top-down you should use the expression to get the angle of movement of the top-down behavior.
It is posible to use just one view sprite of each instance of the same enemy?
If i trigger the collission with the “view” sprite the variable “chasing” is true and all enemies (that are the same sprite) start to chasing me instead of the one that i trigger.
sorry for bothering again, so my idea is create the vision object on enemy and follow it.
here works, in some way, i can create the vision object for each instance of enemy
but i get infinite copies of the object, and it doesnt works with trigger once because only create the vision object on the first enemy.
‘Trigger once’ and the loop-conditions don’t work together. I would probably just create the vision-objects at the beginning of the scene and not bother to create and delete them based on the enemies’ distance to the player.
If you want to do this, though, you could just check the distance of enemy and player first (here you should add a Trigger once-condition) and then, as a subevent, you could add the loop for creating and deleting the objects (you would need it twice: for creating the field of view an for deleting it for all enemies).
Yes, you’re right. It took the events from the “Basic AI with pathfinding”- example.
But I still don’t understand how I can set the ‘For each’-condition?
You can right-click on an event block → Add → Add For each object. Or you go to the upper right corner in the event editor and click the icon that shows a plus within a circle: