playMaker

Author Topic: Set Visibility on everything outside a trigger area  (Read 3665 times)

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Set Visibility on everything outside a trigger area
« on: October 04, 2012, 05:26:40 PM »
Here's a tricky question.

I've got an isometric game (think Alien 8 or Knightlore. If you're under 35, Google them  :) ), made up of different "rooms" each of 8x8x8 in size

I'm currently mapping it out as one scene in Unity while designing the levels in 3D space.

What I need is a way of making a trigger box of 8x8x8 in size that, on enter, turns off the mesh renderers on everything "outside" the current room. (so you can't see what is in the room next door)

I'm thinking Set Visibility.  But it only works on one object at a time..  And my "rooms" are made of many objects....

I already solved the issue of switching to a new camera per "room" - that was relatively simple (using Jean Fabre's "Cut to Go Camera" action found on here. 

But this is a bit of a headache and I'm not even sure if it's possible.

Any ideas?



kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Set Visibility on everything outside a trigger area
« Reply #1 on: October 05, 2012, 05:06:24 AM »
this is actually quite tricky. A broadcasted global event may help you, if you put in a condition that made it only work on stuff in different rooms... maybe based on triggers in each room which write a list of gameObjects to be excluded from the event. Then when the event is called, each gameObject checks whether it's in that list, if it is it won't do a thing, if it's not, it'll become invisible.
Best,
Sven

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Set Visibility on everything outside a trigger area
« Reply #2 on: October 05, 2012, 05:30:50 AM »
try using layers, not sure if you can do this but in the camera settigns you can set what layers are renderable, if this can be done at run time (probably can) and unity can access them then this will be your quickest way, alternatively use a on collision enter and exit to determine when it is turned on and off.

you could try moving each room to a none renderable layer too using the collision method.

alternatively do some fancy UI work to render black (or what ever you want) over everything that isnt wanted, could be in a secondary camera like ngui does.
Or above everything else  (as its 2d wont be an issue with perspective) and turn them on and off instead of the objects themselfs, this wont help performance but if its anything but mobile development it shouldnt be an issue.

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Visibility on everything outside a trigger area
« Reply #3 on: October 05, 2012, 05:41:35 PM »
Thanks for the input chaps.

I've tested with layers.  I've taken one room, manually selected all objects in that room, assigned them a layer called "Visible Room" and then used the camera in that room to only render "visible room"

Now this works well as I can no longer see the adjoining room, it's exactly what I am looking for.   But, I need to find a way to use variables or something to change which objects are in the layer "visible room" and make that dynamic.

Otherwise, i'll have to manually select each object in each room, assign them onto a differently numbered layers, and this will mean I can only have 31 layers (rooms) in total, which won't be enough.  Also, as I'm still in the process of designing the rooms, I'd have to keep manually defining the which objects are in the
layers when I make a change. 

I think my programming/playmaker knowledge has reached its limit on this one!  I'll have a stab at it over the weekend and see what I can come up with, any further suggestions/elaboration appreciated.

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
Re: Set Visibility on everything outside a trigger area
« Reply #4 on: October 05, 2012, 05:54:53 PM »
Make a parent GameObject which contains all the object within a single room. Do this for each of your rooms.
Use something like the the Get Next Child action in a loop that will parse through all children of this parent GameObject, and for each child within the loop, set its layer (not sure if there is a PM action for this already, but the API command is gameobject.layer = 1).

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Set Visibility on everything outside a trigger area
« Reply #5 on: October 06, 2012, 02:15:15 AM »
I was thinking about parant objects, if that works great but I have had a few issues in the past.

so instead if that doesnt work you can use the tag feature now to tag all objects in each room, select all by tag and then move to the visible layer, its possible but not sure with playmaker, I have a custom script that searches for all objects with a tag and uses it for other stuff, if need be I can look into adapting it for this (but with my limited skills that may take a bit) so I urge you to look around playmaker see if its not already there.

.... thats if dasbins suggestion causes issues. as his would be the best :P

stansdad

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Set Visibility on everything outside a trigger area
« Reply #6 on: October 06, 2012, 12:22:02 PM »
Ok cool, I shall return to this I think once I have finished all the level design, that way I will know which objects will be in each room.

I already have my ground components tagged "ground" in order to help me with the controller function.  Perhaps I'll add an empty gameobject to each one and tag that as well.