I’m developing a simple tank shooter game.At the beginning I have created an event to create the enemy object in position,but when I started to work on enemy AI it caused some problems,so I decided to not create the enemy at this stage,only drag 'n drop from list and once the AI works I go back to create the enemy on the fly.I have deleted the create enemy event and dropped 2 enemy in to the scene from the list.
-when I destroy an enemy, for some reason a few bullets still created in that position where I have created an enemy before.but there is no enemy created this time,even the enemy create event is deleted and there is no event to create bullets after an enemy destroyed.
-if all the enemies destroyed,the game crashes,but only if you destroy the enemy on the left side first.If you destroy the enemy on the right side first,the game don’t crashes
-the game in preview and compiled game behave differently.The above problems occurs in preview.
In compiled game there is a bit different .If the right enemy see you,all the enemy start shooting a few bullets,if the left enemy see you only the left enemy start shooting.Once you destroy an enemy it create a few bullets in the position of the other enemy,not at the “ghost” enemy this time.And the game crashes no matter which enemy is destroyed first.
So,when you start the preview,first go up to the enemy on the left side to let the enemy to see you.Control the tank by WASD and rotate the turret with your mouse.Wait until the enemy start shooting and than destroy it by left mouse button.Once the left enemy is destroyed,you have to see a few bullets coming from the left side of the screen where originally I created an enemy,but this time no enemy created which is right,but the bullets is created there. Then destroy the second enemy on the right side,and the game crashes.
This is not the first time I’m experiencing similar issue,but the first time it freaked me out.
Sometime if I make changes in events,the previous settings still functioning even If I have deleted the event and I can’t do nothing about it than create a new project and start the event sheet from scratch.I can’t remake the problems, they just randomly occurs and stay whatever I do,like this time.
There IS an event to create the bullets. It’s event 17: You create a bullet when a view is colliding with the tank.
Good. But if an enemy is destroyed, there are still some views that used to be linked to this enemy. When these views are colliding with the tank, actions of event 17 are launched ( all the conditions are true! ):
First, GD pick all “enemy” objects linked to the view: i.e: None.
Then, you asked GD to create an object at the position of the enemy. Sadly, there is no enemy object, so enemy.PointX() and enemy.PointY() returns 0: i.e: GD create the object at position 0;0.
So two solutions:
When you delete an object, make sure to delete the views associated to the object.
In event 17, instead of taking into account “enemy” objects in the actions, do it in the conditions. The condition will be false if there is no objects picked ( i.e: If no enemy objects are linked to the view ).
Also, i’ve added a for each event to ensure that multiple bullets are created when two views are colliding with the tanks. Here is the modified project: Project.gdg (38 KB)
Finally, you may also consider making enemy go into an “alerted” state, where they will shoot at the player using another event, instead of shooting a bullet as soon as a view is colliding.
Thanks 4ian I didn’t think through this way,I just started panic when I saw the bullets still coming from that position even if I don’t create the enemy in that position anymore.I was like WTF
The game crashed because ,after all enemy destroyed,the view created at position 0,0, (because no more enemies) and when you collided with the view it crashed the game.Well,it crashed for me
It fixed now,no more ghost bullets,no more crash.But I still got the 3rd problem,I’m not completely retarded
In preview everything works perfect.But in the compiled game,if only the left enemy see you,only the left enemy shoot which is what we need,but if the right enemy see you, both enemy shoots. Maybe I can fix it by using an other way to make enemy shoot (alerted),but no such problem in preview.