I have a couple of problems. Been stumped for a few days.
First:
I have Enemy Ships being generated randomly. I have assigned two spots on the ships as “Canons”, both used to fire ammo at my Player ship. I can get the player ship to fire with a key press, but the Enemy ship refuses to fire. I have utilized the code from the Shoot Example but it will not work for me. I have tried many different ways to write the code but alas, much like my ex-wife, it’s not working. Here is there code I am trying to get to work:
I have having trouble getting the Enemy ships to die when HP is reduced. Rather than have the Enemy Ships die with one shot from the player. I have assigned them to take X dmg per Hit from Player ammunition. The Player ammo is colliding with the Enemy Ship hit box and the sound is working but the enemy ship refuses to die. Here is the code I am using:
1-The green words allways (?) represent Objects. The EnemyFireRate variable is “inside” the Enemyship object, so, in the first and second conditions in the second event, you should use the condition: Variable EnemyFireRate of Enemyship >= 2.
Same case in the first and second actions of the second event, replace the point’s position by Enemyship object
Just curious: Why, in the first action, do you use an object and then a point’s position?
2-I guess the variable EnemyHP should be an object variable, not a scene/global one (unless there is only one enemy)
I used the Object and then the Position for the Points I want the bullets to come out of. Each enemy ship has two firing points, Canon Left(X/Y) and Canon Right(X/Y).I thought i had tried Variable EnemyFireRate of Enemyship >+2 and it didn’t want to work. it would only fire from the first ship spawned and then none of the others.
I will keep messing with it. Thanks
Ok, the main idea with object’s variables is that every object can have different values for the same variable: one EnemyShip can have the variable FireRate = 1, and another EnemyShip can have FireRate = 2.
You add TimeDelta() to the FireRate variable of every enemy, this is a real-time counter, but each enemy will have different values.
Then you check if FireRate of EnemyShip >= 2 (GD will use all enemies that have a FireRate variable >= 2) and finally create two objects EnemyAmmo at point’s positions CannonR and CannonL.
Also, when you use object variables to store value for each object individually and run actions on objects based on the value of that variable, better to use for each object event instead of a general event imo, it helps to make sure every condition is checked and every action is run individually for each object every frame.
In case of enemy ammo, in my opinion you should also use linked objects extension to link ammo to the ship or turret object where the ammo is created, as the position and direction of ships\turrets can be different especially if the ships randomly created and turrets are moving. Linked object extension helps to know which ammo belongs to which ship\turret and which ship\turret direction is the direction of which ammo.
I have just made a basic example how to do it. It not random, but I hope it helps to get the idea how to use object variables and linked object extension to shoot bullets.
YAY! Figured it out. Got the preview to work. I had a typo
I had a 0 after a ) and I guess the browser was not seeing it as a complete code line. Removed the Zero and game loaded fine. But, now the enemy ships are not spawning. Well, they are spawning, jut exploding as soon as the hit the screen. I found that using :
Variable EnemyHP of Enemyship <=0
Causes the Enemyship to explode as soon as it spawns, but if I make it:
Variable EnemyHP of Enemyship <0, then the ships will spawn.
THe problem is, and maybe i’m missing something, even after I fix it to <0 the Enemyships are still exploding upon spawn.
If the code is similar to the first one, but with EnemyHP as object variable instead scene/global one, shouldn’t be problem
Try to set EnemyHP of Ship = 120 just after spawn the Ship, to ensure each ship has not 0 HP.
If it doesn’t work, please post a screenshot with the related events (Events with EnemyHP variable or Enemyship object destruction)
If you right click on the enemy sprite in the objects editor and then go onto properties, you will see a tab "variables
". Go into that tab and write a variable “HP” or whatever you want to call it and then put 120 as the value. That way, every enemy will by default have 120 health upon spawning.