Method for detecting closest enemy to hit
Threepwood
Member Posts: 30
Fishing for some ideas here...
Assume the following:
-You have a left/right scrolling game ala Zombieville.
-You can only shoot left or right.
-You can have 6-8 enemies on screen and they can be left/right of you in random arrangement.
-You are shooting bullets/hitscan style weapons and no projectiles (to collide against).
How do you make sure the closest enemy/actor eats the bullet? You clearly want to shoot them in a front to back order based on proximity to the player.
Am I really going to have to create X number of global X postion game variables, and another variable to determine if that pre-determined variable has been set and should be compared against, then in the code loop though 6-8 'if' statements and set a flag when i sort of bubble sort to the closest X position via the magnitude function?
Gotta be an easier way. Why doesn't GameSalad support basic arrays?
I'm new to GS so hopefully am missing something really simple.
Assume the following:
-You have a left/right scrolling game ala Zombieville.
-You can only shoot left or right.
-You can have 6-8 enemies on screen and they can be left/right of you in random arrangement.
-You are shooting bullets/hitscan style weapons and no projectiles (to collide against).
How do you make sure the closest enemy/actor eats the bullet? You clearly want to shoot them in a front to back order based on proximity to the player.
Am I really going to have to create X number of global X postion game variables, and another variable to determine if that pre-determined variable has been set and should be compared against, then in the code loop though 6-8 'if' statements and set a flag when i sort of bubble sort to the closest X position via the magnitude function?
Gotta be an easier way. Why doesn't GameSalad support basic arrays?
I'm new to GS so hopefully am missing something really simple.
Comments
So, for example, how would you implement a pistol/bad guy relationship in zombieville?
Could see making a very fast moving, invisible, projectile but that's so hacky and it would probably be bad for a machine gun that shoots quickly (lots of spawing actors etc).