AI and Line of Sight for enemies.

mgdotnetmgdotnet Member Posts: 17
edited June 2014 in Working with GS (PC)

Hi all,

I have spent a good amount of my week researching this. I know enemy AI is unique and rarely are two games alike. This is what I am working on;

I am working on an over the head view game. The actor (lets say hero) will be running around the level trying to kill the bad guy. So I will have the hero, target, and the enemies. The enemies will be the guys holding the gun and will be on the look out for the hero. The enemy will be (in basic terms) a circle, with a cone (line of sight), and that cone will be where his eyes are. If you run into the cone, the enemy will shoot and chase you. I have found some basic tutorials showing when you get close to the enemy, it will chase you x/y, however, I need some line of sight tutorials that can help me with that. The enemy can not see through wall, therefore, the cone (which I would like to make transparent (not 0 opacity) wont be shown if there is a wall.

I hope I am making sense. I also hope someone can help me with this.

Thanks for your time,

MG

«1

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @mgdotnet‌ -- would you consider thinking about it in just the opposite way? The visual system is a passive reception system. It does not send out rays (or cones). It simply detects photons that enter the eye.

    For example, you could have the hero emitting photons. (In reality, objects don't emit photons, they just reflect them. But you can ignore that issue.)

    Then, when a photon strikes the enemy, it turns to the direction of the photon and starts firing its weapon.

  • mgdotnetmgdotnet Member Posts: 17

    Thanks. However, the point of the game is not to be seen by the enemy and omly kill the unarmed target. I wouldnt want the hero to attract the enemy.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @mgdotnet‌ - I think @RThurman‌ was saying that the hero would be the one shooting out the photons, and if it hit the target enemy, the enemy would know to turn to that direction as if it has seen the main player.

  • TosanuTosanu Member, PRO Posts: 388

    And with that suggestion, walls can more properly be used to block the path of the "photons" with a destroy on collide rule.

    Remember, in games, the rule is "create the illusion that something is happening."

  • mgdotnetmgdotnet Member Posts: 17

    Thanks.

    Heres a questions.

    If I am standing behind the enemy, looking at his back (per say), the photon would hit him and hes turn around shooting at the hero, yes?

    Basically, what I could do is if the hero stands on the cone, the enemy would attack.

    Theres a game called ultimate assassin, im creating something like that with more features and stuff

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @mgdotnet‌ -- here is a quick demo of the idea. I am sure the same idea can be implemented in many different ways.

    Drag the green hero slowly around. You can barely see some semi-transparent photons being emitted from the hero. The photons can't pass through walls. When a photon strikes the enemy, it will turn and fire a bullet in the direction of the hero.

  • ArmellineArmelline Member, PRO Posts: 5,354

    @RThurman said:
    mgdotnet‌ -- here is a quick demo of the idea. I am sure the same idea can be implemented in many different ways.

    That is an insanely clever method. Seriously, respect for that lateral thinking :D

  • mgdotnetmgdotnet Member Posts: 17

    I will take a look and let you know what I think. Thanks.

  • mgdotnetmgdotnet Member Posts: 17

    Thanks @RThurman‌. Interesting concept, however, even if the enemy is facing another direction he will flip around and shoot. This really isn't a great line of sight solution, especially for what I am looking for. Perhaps I can play around, ill see what I can do.

  • mgdotnetmgdotnet Member Posts: 17
    edited June 2014

    I think I can constrain another actor to the enemy and if the photon hits that, he will shoot. I think that will be the best way to do it. One thing I noticed is the enemy sometimes spins out of control while shooting.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @RThurman said:
    mgdotnet‌ -- here is a quick demo of the idea. I am sure the same idea can be implemented in many different ways.

    Drag the green hero slowly around. You can barely see some semi-transparent photons being emitted from the hero. The photons can't pass through walls. When a photon strikes the enemy, it will turn and fire a bullet in the direction of the hero.

    Woah! Top notch! This needs to go in the Spare Code thread! Thanks for sharing!

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited June 2014

    @mgdotnet, going with @RThurman 's cool concept, but reversing the method ...

    ... I suggest that the enemies fire out a limited number of photons along the angle and width of the imaginary cone (facing direction).

    Their travel distance can be controlled by a timer to simulate "fog of war" for the enemies.

    Photons obviously collide and destroy on contact with obstacles.

    If a photon hits the hero, it communicates this to its spawning enemy, which in turn can then open fire.

  • mgdotnetmgdotnet Member Posts: 17

    @Hopscotch‌ I like this idea and I think it would work a lot better.

    What makes the ultimate assassin game so great is the line of sight will change on the enemy, either get better or worse. Makes for a better game.

    http://armorgames.com/play/11849/ultimate-assassin-3

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @mgdotnet, well the above system can simulate that. When a photon reaches the hero, the enemy is alert for a short time (or fires if in range), then returns to normal if no further photons are able to reach the hero.

    The alert time should coincide with the spawn rate of the photons.

  • SocksSocks London, UK.Member Posts: 12,822

    Here's another method, create a line between the enemy and the hero - if the line collides/overlaps with an obstacle then the enemy cannot see the hero.

    Drag the little pink actor around (the hero).

    https://www.mediafire.com/?270r18b2mh2wi4i

  • SocksSocks London, UK.Member Posts: 12,822

    @RThurman said:
    mgdotnet‌ -- here is a quick demo of the idea. I am sure the same idea can be implemented in many different ways.

    Drag the green hero slowly around. You can barely see some semi-transparent photons being emitted from the hero. The photons can't pass through walls. When a photon strikes the enemy, it will turn and fire a bullet in the direction of the hero.

    Nice ! :smile:

  • mgdotnetmgdotnet Member Posts: 17

    @Hopscotch‌ - How would I create the cone for the photons to travel inside? Also, the enemy would travel around the level in a random() method and occasionally rotate (in random) and have the photons continue to shoot in that cone.

    @Socks‌ when I try to open your file, it says it was created in a newer version. I am on 0.10.5

  • mgdotnetmgdotnet Member Posts: 17
    edited June 2014

    Ignore the cone effect. That is actually a very easy fix! @Hopscotch‌

    I also got the file work @Socks‌

  • SocksSocks London, UK.Member Posts: 12,822

    @mgdotnet said:
    Socks‌ when I try to open your file, it says it was created in a newer version. I am on 0.10.5

    Yep, just noticed you were on PC ! Whoops !

    Here's a video of the project in full flight . . .

  • mgdotnetmgdotnet Member Posts: 17

    @Socks‌ Finally got it to work on the PC. Its a very cool concept, but again, I do not want the enemy to attack if I am behind him.

  • SocksSocks London, UK.Member Posts: 12,822

    @mgdotnet said:
    Socks‌ Finally got it to work on the PC.

    Good ! I saw your reply only after I had made the video ! :)

    @mgdotnet said:
    Its a very cool concept, but again, I do not want the enemy to attack if I am behind him.

    Yes, I understand, it was just an example of the line concept, you could adapt it fairly easily - so that the enemy 'scans' (sweeps the line using a sine wave through a pre-defined arc of a few degrees) for the hero.

  • mgdotnetmgdotnet Member Posts: 17

    @Hopscotch‌

    I got the cone working. Moving the enemy is easy, rotating it also easy, but it looks dumb , will have to rotate on a timer i think. im not sure.

    Since I got the photons flying out of the enemy, I am working on if it hits the hero, the enemy shoots. I am getting if the photon hits the hero, it spawns a bullet, but the enemy doesnt shoot it.

  • colandercolander Member Posts: 1,610

    @RThurman is the demo you attached up the page still there? I have tried reloading several times but it doesn't show up.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @mgdotnet, does the photon set a game.attribute indicating that it found the hero? Then let the enemy spawn a bullet and set the game attribute to false again.

    Depending how you have your rule set up, you may have to wrap it in a Timer so that it checks the game.attribute repeatedly.

  • mgdotnetmgdotnet Member Posts: 17

    @Hopscotch‌ I am still new with gamesalad, very new actually, I will do some researching to see if I can find a tutorial on this.

  • HopscotchHopscotch Member, PRO Posts: 2,782
  • mgdotnetmgdotnet Member Posts: 17

    Thanks, I am still working here. I got it so the photons destroy after a certain time, but respawn new ones before they destroy. This will be for the enemys length of line of sight.

    Thanks for your time, have a good night/morning.

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited June 2014

    @mgdotnet, still made a quick version, hope it gives some pointers.

    Move the Hero with the mouse.

    Enemy only have basic movement, some waypoint system will need to be implemented.

    Windows Version:

    http://www.mediafire.com/download/1spwzn136xzp9d5/LOS0008.zip

    Mac Version:

    http://www.mediafire.com/download/5glhdwbwbakri4x/LineOfSight0008.gameproj.zip

  • mgdotnetmgdotnet Member Posts: 17

    Thanks. I will play around with it. Looking to have the actor move and rotate randomly, and then also chase hero if detected. lot of work. ill try to figure it out from here.

  • mgdotnetmgdotnet Member Posts: 17

    @Hopscotch‌

    If I did a way point system, lets say I have a total of 100 levels. Maybe ill need 200 enemies or more. Will the game lag any?

Sign In or Register to comment.