Destroy outside


#1

Hi guys this might be something so simple but i can figure it out haha
i have added the destroy outside behaviour to my bullet for example.

i use a camera to follow the player but when i fire the bullet and it goes past the camera view , it is still hitting the enemy who is outside of the camera view lol

any way to make it so if it goes out of camera view it deletes the object ?


#2

You could try timer events.
Do a timer condition and after 5’’ for example delete the object “bullet” or when collision with enemy happens


#3

the problem is that is i do a timer that after 2 seconds the bullet deletes and then reset the timer, the timer has already reset and begun again so it could be already on 1 second and then delete next second which doesnt give it time to get to end of the camera lol unless im doing it wrong

and the bullet does die when it hits the enemy however because the camera follows the player and the enemy is made to go to that player at say less than 400 pixels someone could just stand further away then that so that the enemy is out of the camera view and fire bullets at him without the enemy running at them. but if i could get it so the bullet deletes when out of camera view then it would not reach the enemy


#4

In the current version of GD (beta 75) the behavior does not work, will be fixed in the next release:


#5

ah i see thank you :slight_smile: if anyone has anyway around this issue it would be much appreciated


#6

Create a (or multiple) sprite that is always just outside the screen border.

Add an event as follows:
Condition: ‘on collision’ between the object you want to destroy and the sprite you’ve created to stay outside the screen
Action: Destroy the object

Hope this makes sense. Else let me know… I’ll upload an example


#7

hi thank you for the answer and that would probably work :slight_smile: but i figured out before using

the x position of weapon 2 is > cameraX() + 580 action - delete weapon 2

a big thank you to everyone who tried helping me :slight_smile: