In a previous design diary, I talked about screen boundary detection. What is an easy way to determine when an object has left the screen so that you can act on it?
I discovered a new solution that is incredibly cheap and easy with a few caveats:
- You will not know which edge of the screen the object has passed (so it won’t work for wrapping objects around on the screen)
- You only get one notification when the object moves beyond the camera (unless you setup a timer)
How to Implement in 2 Steps
1. For each model that you want to get boundary notifications for, open the model properties and under general, check Frustum Activation.
2. In one of the AI models attached to your object, implement the onDeactivate handler.
Now any time an object with this AI leaves the screen, onDeactivate will be called. Similarly, onActivate is called when the object enters the screen. For us, this made destroying rockets at the screen boundary as easy as:
-------------------------------------------------------------------------------- function whistlePeteAI.onDeactivate ( ) -------------------------------------------------------------------------------- scene.destroyRuntimeObject ( application.getCurrentUserScene ( ), this.getObject ( ) ) -------------------------------------------------------------------------------- end --------------------------------------------------------------------------------
Be the first to comment