Im creating a level in which stationary/rotating/moving enemy game objects have a line of vision and if the player goes in that line of vision, the game is over. It’s a top down 2D game. How do I go about creating a script for that?
For rotating enemies, the line of sight will move with and the moving enemies, the line of sight will move with them as well.
You can give any object you want to have a field of view like this. In this example, it first checks if the objects are close enough, then if they are it checks if it’s in the field of view of the player object based on the player’s look direction and how wide its fov is.
To add line of sight you need to add a collision detection raycast with geometry step.
EDIT: I got it to work! Only thing is that it rotates on the center of the object. Any possible way, from the code that I added, that I can get it to rotate on the left side of an object. The game object is a light sprite (a flashlight) and I’d like it to rotate from the one end of it instead of the center. Kind of like how your hand rotates on your wrist. Thanks
function init(self)
go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 45, go.EASING_LINEAR, 4)
end
Sorry for bringing this back up, I am having trouble with the angle part of it. It’s not rotating at the 45 degree angle I’d like it to. In my code above, 45 is the degree right?
It rotates but the angle is thrown off. I have it at currently 1.75 instead of 45 and it’s hitting what would be 60 degrees. Unless I just didn’t position the sprite right but I think I did. The sprite rotates at its tip, like you said, so maybe it’s different from there?