Skip to the end for the basic jist.
I want to add a hitbox to an attack with scene.addObject(hitbox, pos). My plan is to get the collision list of the hitbox, check if “target” is there, do damage to target, then add target to a hitList so i can make sure not to inflict more damage to it if it’s in the list.
So I have my hitbox on layer 2, it has a collision sensor connected to a python script that just defines the sensor (it just feels like it’s more activated this way)
When I add the hitbox I WANT to do:
#Define the hitbox
hitbox = scene.addObject("hitbox", attack.position, 1)
#Get its collision sensor
col = hitbox.sensors["Collision"]
if col.positive:
#Check for the player then do damage and add to hitList to "deactivate" it from further damage
if "player" in col.hitObject:
target = col.hitObject
_doDamageAndTheRestOfTheFunctions(target)
It recognizes hitbox.sensors as “Collision”, but when I check for collision on said sensor it wont respond with anything! Always None. I can see the hitbox hitting the target, but it wont find a hitObject. I assume it has something to do with the sensors of the original object not connecting with the added object…
I can only get a hit response by doing this:
scene.addObject("hitbox", attack.position, 1)
col = scene.objects["hitbox"].sensors["Collision"]
#Now I have to reference the hitbox through the scene
And now I can’t have more than 1 hitbox active at a time, if I do, like if multiple enemies spawn their atkboxes agains the player, the damage output is multiplied by how many enemies are attacking…
Basically: I can’t seem to access the collision from instanced objects added via scene.addObject, even though the added object is dynamic and has a collision sensor connected to a script.
Hope you understand and can help, thanks <3