#how do you go about projectiles that go through enemies but can hit every enemy only once?
12 messages · Page 1 of 1 (latest)
reverse it. have a list of enemies a bullet in the bullet has hit don't damage them again if they're on the list
structs still the way to go?
i'd use an array
This function checks if the given value exists in the array, or in a part of it. It returns true if the value exists, or false if not.
Arguments
array: The array in which to look for the value
value: The value to look for in the array
offset: The offset, or starting index, in the array. Setting a negative value will count from the end of the array. The starting index will then be array_length(array) + offset. See: Offset And Length
length: The number of elements to traverse. A negative value will traverse the array backwards (i.e. in descending order of indices, e.g. 2, 1, 0 instead of 2, 3, 4). See: Offset And Length
//create
hitlist = []
//Step
var enemy = instance_place(x,y, oEnemy)
if !array_contains(hitlist, enemy){
enemy.hp -= 1 //or wahtever
array_push(hitlist, enemy)
}
instance_place_list is the same idea, just loop through the list, add them to the hitlist array
kk tyvm
btw
just as a design principle
you wanna have the fewer object check for the many object
1 player checks for walls, not 100 walls checking for the player (most walls won't be any where near the player)
1 bullet checks for enemies, not 100 enemies checking for a bullet (most of them won't find a bullet)
save on operations and less data to manage