Preventing an object from spawning off-camera
MonjiO
Member Posts: 20
So, I'm working on a shooter game and I'm trying to prevent enemy attacks from coming from offscreen, while still destroying themselves once they reach the edge of the screen. I've got the camera as an object with its own dimensions and it is detected for the purposes of player movement.
Detailed Explanation:
The player is moving from left to right, with enemy projectiles coming from right to left. Currently, I have a rule stating:
If self.position.x < game.CamOriginX
Then Destroy Actor
So the projectile is destroying itself once it hits the left edge of the screen. However, currently, enemies are able to attack based on timers meaning that attacks can (and are!) coming from outside the camera range.
So, my question is basically how best to prevent this sort of behavior. Should I redo how enemies are attacking so that they won't attack while offscreen? If so, how? Or is there a way to make the projectile destroy itself while not in the camera's view?
Detailed Explanation:
The player is moving from left to right, with enemy projectiles coming from right to left. Currently, I have a rule stating:
If self.position.x < game.CamOriginX
Then Destroy Actor
So the projectile is destroying itself once it hits the left edge of the screen. However, currently, enemies are able to attack based on timers meaning that attacks can (and are!) coming from outside the camera range.
So, my question is basically how best to prevent this sort of behavior. Should I redo how enemies are attacking so that they won't attack while offscreen? If so, how? Or is there a way to make the projectile destroy itself while not in the camera's view?
Comments
if spawner is <= CAMERAPOSITION
spawn
and just set cameraposition to whatever value you want, the camera's exact position, or maybe 100 higher so they spawn a little offscreen?
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left