The new sensor has been altered to look more like a typical enemy sensor seen in games.
To create this I needed to create a script which would create the shape and change the position when needed:
The reason I needed to create a script is because, the engine doesn’t have a draw_triangle_color_width function, it only has a draw_triangle function. This means that I could create a triangle, but I couldn’t alter the color or width.
I also made a few adjustments to the script above, which is y1-1 (line 13) and y1+1 (line 15). By adding this small adjustment, it made it look like the sensor was coming from the enemies eyes and not just a triangle in front of the enemy.
Once done I added the new code into the draw event on the guard:
The variables I’m using above are these (create event):
Once made I needed to update my sensor. This took quite awhile to figure out, because I didn’t know scripts could use arrays and I didn’t know how they worked. Anyway this is the inside the script:
There’s a problem with this script though, the code requires an array and the old sensor detector was a 2D Vector variable. To fix this I changed the default variable to an array with specifically 3 values. I then did this in the draw event:
The draw_triangle_detector works similar to the collision_rectangle function, but it requires 3 x and y inputs and not 2, doesn’t require a precise input, but it does require an array input and a variable storage.
The shape a collision was complete, but I needed a way to detect it, so I add in a for loop in the step even of the guard:
With all this done, the question you might have is why do all this?
The answer to that is, that there is no function built in and with the script I can even add a rotation and change the direction if I altered the script further.
By creating the script instead of putting it in the code itself, I have improved the performance and reduced time taken, if I wanted the sensor on multiple characters. I can also use it for a melee attack.