GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Switching Between Multiple targets

GrapesforalGrapesforal Posts: 3Member
edited November 11 in Working with GS (PC)

I am making a simple shooter game. I have a spawner that spawns enemies (same actor). These enemies are all tied up in a table so they function independently from one another. The problem: The player is only able to shoot the first spawned enemy, once that enemy is dead the player is then able to shoot the next spawned enemy. Not ideal. My idea is to calculate the distance between the enemies and the player on my table. The game will then locate the row with the lowest value "distance" and get the corresponding X and Y coordinates and fire appropriately in that enemy's direction.

Currently, I've calculated the enemies distance and put that value into the table:
This works fine. Each enemy has their individual distance calculated using:

Loop
change table value
Game. Table
Row: Self. Row #
Column: Distance Value: magnitude( game.PlayerX-self.EnemyX , game.PlayerY-self.EnemyY )

Issue occurs when I attempt to locate the lowest value
Timer Every 0 Seconds

Loop Over table
Loop. Game. Table : rows
Start Index: First Cell
End index: Last Cell
Store Index in Atrribute: Self. Identify Nearest

Rule
if Self. Nearest > TableCellValue(game.table, Self. Row #, "Distance")

do

Set Self. Nearest to TableCellValue(game.table, Self. Row #, "Distance")

I have of course set the attribute self. Nearest to = 9999

the value seems to update and then freeze then update once more. Id like it to constantly stay updated ofcourse.

any help would be greatly appreciated.

Comments

Sign In or Register to comment.