#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Hide Actors from other Actors?

Posts: 186Member, PRO

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

• Posts: 672Member
edited May 2017

@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?

• Posts: 672Member
edited May 2017

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?...

• Posts: 11,899Member, Sous Chef, PRO, Senior Sous-Chef

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

• Posts: 8,977Member, Sous Chef, PRO, Bowlboy Sidekick

@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.

• London, UK.Posts: 12,822Member

@Japster said:
. . . a (rough and) easy solution I thought about for Gravity Star was to simply use an actor to 'draw' an invisible line of sight

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.

• London, UK.Posts: 12,822Member

Found it . . . . scroll down to see the demo @RThurman attached to his post:

• Posts: 8,977Member, Sous Chef, PRO, Bowlboy Sidekick

@Socks going the extra mile.

• Posts: 9,914Member

I think the path finding behavior could offer a solution but never invested much into working with it.

• Posts: 672Member

I think the path finding behavior could offer a solution but never invested much into working with it.

@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!

• Posts: 186Member, PRO

@Socks said:
Found it . . . . scroll down to see the demo @RThurman attached to his post: