How do I create an object (ray) in front of all instances of a sprite?

How do I create an object (ray) in front of all instances of a sprite?

I’ve coded an AI test where enemies move from left to right between markers, along with the creation of the ray (this will be easier than showing the actual game). So, I did “at the start of the scene” and “select all objects,” and as an action: I created the “Ray” object at the X and Y position of the “enemy” sprite.

Unfortunately, the object is only created for one instance of the enemy and not for all enemies. What’s wrong, please?

I’ve attached a photo of the test because I don’t know how to share the project JSON file here. Could someone also tell me how to do that?

Thanks!


If you still want to learn how to do what you are trying to do most ppl here can explain it
BUUUUUUT

In your case i think what you are actually looking for is at 2:42

Hi, usually ZeroX4 is spot on with his suggestions but in this case I am not sure if what you want is covered in the video. As far as I understand you want to attach a cone of sight/ray to the enemies.

You need a ‘for each’-event. The ‘Pick all enemy objects’-condition does not work this way.
Something like this:

You also have to make a link between the enemy and your ray, otherwise all the ray-objects will move with only one enemy. The easiest way to do that is to use the sticker-extension (there is also the ‘link two objects’-action but this is a bit more tricky to use). You just stick the ray to your enemies after creation and each ray will move with each of the enemies.

Hi, thanks for replying. Both of you have helped me. I had indeed already seen the video, BUT I hadn’t noticed the “for each” element that you mentioned, Drone. I wasn’t even aware of its existence, and that’s where the problem was. Drone, your example worked. I’m not using raycasting because I wanted to visualize the enemies’ vision cone. I will now be able to use “for each” for many actions related to my enemies. However, I still have a question that pushes the reflection a bit further based on the example I provided here: How would you make the vision cone flip horizontally (point in the correct walking direction) individually for each enemy, considering that in this case, enemies may or may not be flipped horizontally at the same time?

You have 2 actions each for flipping horizontally enemy and not
Duplicate each action and change object to your vision cone
So they flip accordingly to enemy

And as i understand you just want to make patrolling enemies
What this video offers is more performance friendly
Rather than having some object created and attached to each enemy

BUT if your scene is not too big and you did not overload it with a lot of logic it should not really matter

Yes, I finally opted for raycasting, even though it’s a shame not to be able to visualize the ray in the game’s preview. Indeed, my enemies now patrol, shoot when they spot the player, follow the player, jump over obstacles, and turn back when they’re near a void. Thank you both so much for the ‘for each’