I am currently trying to find ways to have the least amount of parts within the workspace at any given point in time. This is so I can have a persistance with smaller objects I create through the course of play, but don’t actually need them to exist at the current point in time.
- Shotgun shells
- Ragdolls
- Exploded barrels
- Spaghetti noodles I dropped on the floor
My method of doing this is by creating a bounding box and calling it a ViewCube, everything within the room’s dimensions belongs to that ViewCube, and is pre-set as belonging to it. If I add objects I can check quickly if it exists within the space of a ViewCube. This should allow me to save all the little bits and bobs a player leaves through a level without getting taxing by calculating things that won’t be seen anyway.
However, I only have access to WorldToScreenPoint to see if it is within the bounds of the screen, this doesn’t tell me if what I’m looking at is actually being drawn.
In order for the view cube to now work, I take the Vector3 of all of its normal faces and check it with this method WTSP. To see if any of those points are actually in view I would need to ray, but if I look at this object at an angle which doesn’t show any of those points, despite being on screen, it will be refered to as not on screen.
I can up the amount of points each ViewCube has, but for a large level that starts to get out of hand per frame.
The aim is to only de-parent and re-parent things that are absolutley needed for a particular area, without doing this action an absurd amount of times.
Here is an example of what I’m attempting to achieve;
Running without FE so I can have a server/client view.
As you can see from the clip, there is an issue where even when I can’t see a room, its still considered OnScreen, and when I still can see a room its no longer OnScreen.
There are a ton of gameplay uses for this as well, from stopping enemies attacking you while you aren’t looking at them to spawning them where you can’t see them, to trigger events.
I’ve been looking at making an interaction module for my game, where one of the interactions would be looking at something and an action happening, it would be rigged like this.
- Have two parts
–The object we are looking at
–The object we need to see it through - Use WorldToScreenPoint to find if they are within N amount of pixels to eachother
- Use the Z property returned to us to make sure we are looking through them in the correct order
- Cast rays ← Holy moly, if I have lots of sight interactions in my game, this could get costly at certain angles
If I instead could just check if they are both being drawn, it’d be a lot easier, especially if that information already exists!