When object 'sees' another object

Is there a way to code a character so that if it ‘sees’ another character, something takes place? For example, a bad guy is chasing a good guy, but when the good guy goes behind a wall, the bad guy can’t chase him anymore. Thanks!

Yes, of course, use the event “Collided with”. See the picture below

Good luck.

Hi and thanks for the quick reply. However, this is not what we meant. If an object is in the field of view of another object, can it react? However, if there is a wall between the two, there is no reaction.

Hi @Kelly_Nickell, there are probably a few ways you could do this technically, but none are simple.

One creative way to do this in CoBlocks would be to constantly fire transparent items from one character to another, and if they hit something on the way, you’ll know there’s something in the way.

If you’re using Scripting, it should be possible to use RayCast to make this happen.

Geoff @ TechLeap

1 Like

Hi @Kelly_Nickell,

You can remix CoSpaces Edu :: [API] Raycast to see how to use the Raycast API. In the Raycast.cast() method, the origin would be the position of your initial character, and the direction would be the position of the other character. You could check whether the item you hit is the other character, and if not, you know that some other object is in the way.

Geoff @ TechLeap