Author Topic: More with Sight Tests  (Read 522 times)

Galavant Garde

  • Full Member
  • ***
  • Posts: 164
  • Cayelan Mendoza
    • View Profile
    • Galavant Garde - Dark Electro Disco Pop
    • Email
More with Sight Tests
« on: December 18, 2017, 05:37:48 AM »
Hullo there (probably one for you Brian), so I remember once upon a time you could set how many rays and which angles/offsets etc for sight tests, but that's all gone now under a simplified but much better sight test command.  But, I don't really get what it does so I'm not sure what's the best way to achieve what I'm trying to achieve.

Let me explain ;-) I normally do sight tests when my bots are looking at the player.  As a result, they work fine!  However, I want my bots to have better peripheral vision, not just when they're staring straight at the player.  So what I do is start a watch event on the bots, and when the player is near, it starts a looping chain that checks the angle to the player.  When the angle is within what I think is a reasonable angle for the bot to see (it's like 120) I then do a sight test to see if the player is in the line of sight.  Now, that works fine when the player is dead ahead, but when they're off to the side a bit, the bots usually don't spot the player.  The result is, you can make a break for it out in the open where a bot 'should' be able to see you, but the sight test misses most of the time so you evade them far too easily.

What I did to stop this from happening is, quickly turning on the facePlayer command while doing the peripheral sight test, then turning it back off.  This works, and they're better at spotting the player, however they do this annoying twist at the player then back where they were facing for a split second...i.e. it looks gumby

To make sure I'm using it properly, how does the sight test actually work?  And is there a way to get the sight tests better at peripheral vision checks, or am I best off making my own sight projectiles and offsetting the angle they fire at by checking the angle to the player?  The latter seems manual and clunky, but I'm pretty sure I could do it.

ggadwa

  • Administrator
  • Full Member
  • *****
  • Posts: 208
    • View Profile
    • Klink! Software
Re: More with Sight Tests
« Reply #1 on: December 18, 2017, 08:36:17 AM »
If you set obj.watch.setRestrictSight(angle,rayTrace) where angle equals, say, 120, then you will only get a watch event fired if an object is within 60 degrees to the left or right (and if you set rayTrace to true, only if a ray trace is OK.)

With obj.watch.setRestrictSight(120,true) should automatically duplicate what you are doing below.

You can also obj.angle.rotateTo(ang) to turn directly at the player (you can calculate the angle from the watch event), do the sight, and then turn back to the original angle.  If done within a single call, it won't actually turn the player as you reverse it before the engine runs again.

[>] Brian

Galavant Garde

  • Full Member
  • ***
  • Posts: 164
  • Cayelan Mendoza
    • View Profile
    • Galavant Garde - Dark Electro Disco Pop
    • Email
Re: More with Sight Tests
« Reply #2 on: December 18, 2017, 08:41:43 AM »
Cool, good to know!  I'll give it a try  8)

EDIT - will post the result. I don't think I'll restrict the angle of the watch, as I use it for listening for sounds as well which the bots should be able to hear from any angle.  But I'll try the rotateTo bit

Galavant Garde

  • Full Member
  • ***
  • Posts: 164
  • Cayelan Mendoza
    • View Profile
    • Galavant Garde - Dark Electro Disco Pop
    • Email
Re: More with Sight Tests
« Reply #3 on: December 18, 2017, 08:54:54 AM »
Brilliant Brian, works like a charm  ;D literally transformative in terms of how much smoother the AI works!!

Really good to know about the ray tracing watch thing too - will use that for security cameras or things like that