Homing Missles // Error when target is Destroyed

Homing Missles // Error when target is Destroyed

===========================================

I’m working on a project for a Gundam game that uses homing missles. To lock in on the target the object uses the position of the target versus its own to orient itself towards the object. Pretty simple tracking system, since local movement is localized to forward movements only. (refer to http://solarlune-gameup.blogspot.com/2011/05/python-in-bge-part-8-ai.html )

Anywho, the problem is when the target of the missle is destroyed. To pass the info on which target to track to I had to assign it directly into the object. So when the object dies the rocket is still pursuiting an object that has now been removed from the scene. Since it’s missing from the scene the heat seaker spazzes out and creates some ridiculous lock down error.

How do we account for an object being in the scene…

PsuedoCode

if obj[“lockedOn”] not in the scene:
explode Missle
else:
fly towards obj[“lockedOn”']

What is the function to test for this?

You could send a message if you wanted the other homing missiles to know that the enemy is destroyed. you could use this to make them explode or trigger a script to switch target if possible.

Normally the roket explodes which produces damage on the enemy. Except the enemy is scared to death ;).

Do it like this:
When the rocket is near or collides with the target (or anything else)

  • all objects within a range gets a damage (sensor.hitObject; sensor.hitObjectList) e.g. property “newDamage” = “newDamage” + whatever
  • the rocket ends it’s life

When the enemy (or any destroyable object) has “newDamage”!=0

  • they need to process this damage and remove it from “NewDamage”.
  • if the damage is over the limit -> end your life :wink:

With that method it is not on the missle to destroy the objects but deliver damage.
The objects by themselfes should know how to deal with the damage.

I hope it helps

Thanks for the help!!

the message system worked great for telling the rockets to explode…

there seems to be a problem when the “variable has been freed”

once that happens, there is an error… i handled it for when a rocket is in motion by having the object that it was chasing send it a message…

However, the next homing missile i shoot is still looking for that dead object… i need a way to check if the variable is freed… its not quite the same as being “None”

any insight?

I think what you are looking for is a GameObject’s invalid property. So rather then checking if obj == None, try if obj.invalid.