This site requires JavaScript, please enable it in your browser!
Greenfoot back
Inkflicker
Inkflicker wrote ...

2014/8/14

Line of Sight for Enemies

Inkflicker Inkflicker

2014/8/14

#
I am trying to make a stealth game in which you will loose if an enemy sees you but I have no idea of how to give an enemy a line of sight that will be obstructed by walls and will move with the enemy. If anyone can help I will be very grateful.
danpost danpost

2014/8/14

#
Have an invisible sensor object created for each enemy (this can be done in the constructor of the enemy class with an instance field in the class to hold the sensor) that it can use to detect obstacles in the line of sight. Have the enemy add the sensor object anywhere into the world in the 'addedToWorld' method. In act method, if player is in world, then do the following for checking line of sight: * place sensor halfway between player and enemy; * size width of sensor image to distance between player and enemy (height of sensor image should be two); * rotate the sensor to the angle between the player and enemy; * call a method in Sensor class that return a boolean value indicating any intersecting objects besides player and enemy;
You need to login to post a reply.