Method for detecting closest enemy to hit

ThreepwoodThreepwood Member Posts: 30
edited November -1 in Working with GS (Mac)
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.

Comments

  • ThreepwoodThreepwood Member Posts: 30
    Is there any way to put out a trace along the x axis and know the 1st actor you hit and then deal with it?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    just put a rule in the bullet. When collides with bad guy destroy
  • ThreepwoodThreepwood Member Posts: 30
    No bullet in the world. No projectile. Like shooting a pistol or shotgun in an FPS game. There is nothing that travels to collide against.

    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).
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    You could avoid spawning by having the bullet actor make the trip and then change position back to the gun, ready to make the next trip.
Sign In or Register to comment.