Hide Actors from other Actors?
rainwaterstudios
Member Posts: 198
I'm looking for a way to hide one actor from another actor - i.e. if there is a wall between them, actor1 won't "see" actor2, but if actor1 is in actor2's line of sight, actor2 would chase actor1.
Any ideas on how to implement this functionality?
what would you suggest?
@Socks
@The_Gamesalad_Guru
Comments
@rainwaterstudios Yep, I was working on something similar, no doubt the tagged guys will have an awesome solution, but a (rough and) easy solution I thought about for Gravity Star was to simply use an actor to 'draw' an invisible line of sight (whatever width works best) to another actor - if the line(s) drawn 'collide' with scenery, then line of sight is impaired - there'll be flaws to this if you're not intending to use central points of origin, in which case you'll have to offset your start/end points, but it's a simple (and resource-friendly) solution that's working out for me...
Of course in a 'stealth' type game where you want to judge exact line of sight, you may need to use 2-3 actors to lay down a 'cone' of sight - if all are free of walls etc collision, then clear line of sight is there. If one or more are clear, then only partial sight is flagged? - and of course, if emulating limited range line of sight, you'll either have to use magnitude to ensure a limited distance before kicking in the line of sight / sighting logic, or draw the line of sights along the same angles/vectors, but calculate a closer end point - I leave that bit up to you....
Of course, lines can originate at eyes, or just centre of each actor...
...and if using the 'cone' method, no doubt one of the guys can give the exact calculation required, to ensure the outer lines of the cone match the extremities of the targeted actor's dimensions, based on how far away it is...
PS - You could have used a simple custom collider of a triangle for the cone, so just use the one actor, widen/narrow it accordingly, and even make it a couple of pixels wide to emulate a single line, but unfortunately that would take away the ability to sense partial sight, as you'd only have one collision registered in any collision scenario, so I still think the above should work better?
BTW - the collision checks don't need to be walls - think areas of shadow that can be walked inside, etc, works just as well, as long as the sightlines are colliding with the target and the target is NOT fully colliding within the area of shadow, he can be seen?...
If you haven't yet, search the forums for line of sight as there have been several discussions about this concept before.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@RThurman had a wonderful little demo he posted several years ago (I think it's been that long now...). It's in the Spare Code thread. Check it out.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Yep, that seems to be the best solution out there, I think @RThurman had a pretty cool solution which was similar, he used a kind of ray casting where he 'sprayed' out little particles in the direction of the target and if they made contact (so had a clear path) then then target was visible, I'll see if I can find it.
Found it . . . . scroll down to see the demo @RThurman attached to his post:
http://forums.gamesalad.com/discussion/69713/ai-and-line-of-sight-for-enemies/p1
@Socks going the extra mile.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
I think the path finding behavior could offer a solution but never invested much into working with it.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru - Yeah, I'm thinking about using it for my Gravity Star Rescue Racer game, to add 'intelligent' opponents, as I would have a grid to match each level, and checkpoints - but I guessed as it will find a path to the target, around obstacles, I figured it might not be that suitable for line of sight logic without getting inventive!
Awesome, thanks everyone for the input!