Forum rules - please read before posting.

Preventing the player from seeing through walls/obstacles

I know that this, or something similar, has been asked before, but I've not been able to track down a simple solution to the problem, soooo...

My particular use case:

I have an exterior (3D) graveyard scene, which includes a church that can be entered. The church model is on an "Obstacles" Layer, which I use to prevent the camera from clipping through the scenery

When the player is outside I don't want her to be able to interact with things inside the church, and when she's inside I don't want her to be able to interact with things outside the church (even though in both cases she may be able to see those things - either through the windows, or through the doors when they're open)

At present I'm blocking hotspot access to the objects by using Interactive Boundaries. That more or less works, but it's not entirely ideal because it doesn't use line-of-sight, and in any case it's only really suitable for static objects

I've also just now introduced an NPC character into the equation, a monk who can walk randomly around the scene, and I only want him to be interactable when he can actually be seen by the player, so an Interactive Boundary isn't going to be suitable in his case

My feeling is that I'm going to need to write something to check if he's visible to the main camera, and switch his hotspot on and off, depending on whether he is or not, and perhaps that is the way to go; but this is such a standard problem that I feel it must have been encountered (and presumably solved) many times by other people before now, and that there should be a simpler solution which I just haven't stumbled on yet

So, any suggestions welcome

Comments

  • P.S. I forgot to add in the original post - Hotspot Detection Method: MouseOver


    I've actually gone ahead and written a small routine to do the switching of hotspots on and off (because it seemed like it might be a useful feature to have), and it kinda works. Only "kinda" at present. It successfully detects if an object is visible to the camera (which turned out to be more complicated than it sounds), but I can't seem to get AC to act on the information

    If I do a hotspot.TurnOff() when the object falls outside the camera view then I think that sets the object's layer to "IgnoreRaycast", which means it doesn't get re-detected when it comes back into view; and simply doing a hotspot.enabled = true or false doesn't seem to have any effect on whether the object responds to the cursor or not. It continues to show the object as being interactable whatever the enabled state
  • Don't worry, the solution is much simpler.  If a Collider is on the same layer as Hotspots (by default, "Default"), but has no Hotspot component, then it'll block mouse Raycasts to anything behind it.

    Just place down a CollisionCube over the walls of your building, and you'll prevent unwanted Hotspot discovery.  The 3D Demo scene uses this trick with the "GreenScreen" object to prevent the sword being clickable from the initial gameplay view.
  • Thanks Chris

    I could have sworn I tried that trick, but if I did then I was clearly doing something wrong, because I've just tried it again and it worked perfectly this time
Sign In or Register to comment.

Howdy, Stranger!

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

Welcome to the official forum for Adventure Creator.