Environmental Death

I’m trying to use existing code I have for a proximity mine to activate nearby environmental deaths. For some reason my code does nothing, not even produce errors. The explosion part still works, the physics objects nearby it set it off and it blows them back a bit like it’s supposed to, but it doesn’t trigger the environmental kill. Any ideas?


def explode():    MAX_FORCE = 7300
    MAX_RANGE = 5
    
    scene = l.getCurrentScene()
    bomb = l.getCurrentController().owner
    
    for obj in scene.objects:
        if obj.mass:
            vec = obj.worldPosition - bomb.worldPosition
            if vec.magnitude <= MAX_RANGE:
                hit_obj, _, _, = bomb.rayCast(bomb.worldPosition + vec, bomb.worldPosition)


                #right here is where it tells the environmental kill to activate, but the property doesn't ever increase in                       #value when i test

                if 'enviroKill' in obj:
                    obj['enviroKill'] += 1
                if hit_obj == obj:
                    vec.magnitude = _getForceMagnitude(vec.magnitude, MAX_FORCE, MAX_RANGE)
                    obj.applyForce([vec[0], vec[1], vec[2] + 600])
                
                bomb.endObject()

You structured your if statement in such a way that it glances over the initial statement.

I would make the count go up only when the damage and force are applied with if nesting.

Could you be a bit more clear? I’m not sure how to fix it still

I don’t see any reason why your script wouldn’t work. Are you sure it’s actually being executed when it should be? Do the objects have the proper physics settings so they can be hit by the ray casts?

EDIT: Here’s a blend with your script working. The only thing I changed was remove the _getForceMagnitude function since you didn’t provide it.
mine.blend (451 KB)

hmm I don’t know what the problem is then…I’ll keep messing with physics settings, that’s gotta be it

Do static objects not detect rays? I can’t find anything saying they don’t

Yeah I guess they don’t. Crap now I have a whole new problem. I need this object not to act as if it’s static but not actually be

No, static objects definitely can be hit by rays. Maybe you should post a blend showing your physics setup.

Ok, well thats weird because changing the object to dynamic made it magically start working. Here’s the original broken setup
The problem with it being Dynamic is I can’t have the part that falls parented to the base or else it will trip out. I need it to be static so taht everything stays in place until the variable changes and I can unparent the part that falls. I haven’t written code for the unparenting part yet because I never got there
Blend: https://www.dropbox.com/s/2w2silwv0hp872j/EnviroKill.blend

if obj.mass:

Static objects do not have a mass - because they are static.
Static objects do not have a velocity - for the same reason.
Static objects do not react on any physics.

Static objects can be involved into physics interaction - as obstacle. They will not get any change - because they are static.

If you want an environment reacting on physics interaction, I suggest to temporary make it dynamic. Or you apply the interaction effects by yourself via code (positional and rotational changes)

Ok, thanks Monster