Help with homing script


(Toomai) #1

I dont like being long-winded, but here goes…

I need a projectile to home in on another object and hit it. I’ve done this before using a spinning projectile and some ray/radar blocks, but because the game I’m doing involves a large area, small objects, and projectiles that can’t spin because they’re halos, I need a homing scrpit. I’ve looked for one, but the only one I found doesn’t exist anymore (broken link from 2004). Here’s the idea I have:

if projectileX < targetX then projectileX = projectileX + 1
if projectileY < targetY then projectileY = projectileY + 1
if projectileZ < targetZ then projectileZ = projectileZ + 1
if projectileX > targetX then projectileX = projectileX - 1
if projectileY > targetY then projectileY = projectileY - 1
if projectileZ > targetZ then projectileZ = projectileZ - 1

The problem is that I don’t understand how to work Blender things from Python code. I could read a tutorial, but it’s too hard for me to understand what’s going on. I need almost every line to be explained so I can really get it.

I’d like someone to convert my idea into a fesible script and explain how it works so that I can write other scripts on my own. The whole problem is getting me started.

Hopefully it’s not too much to ask for.


(facemania) #2

Well, I don’t know much about python but you can do this with logic bricks.

Have a “Always” sensor attached to a “AND” then to a “Edit Object” actuator (with the subheading Track To and with “3D” enabled) and also to a motion actuator, this will make the object track to an object and move towards it :slight_smile:


(Toomai) #3

That is a good idea that I hadn’t thought of, but that means I can’t have the projectile home in on the closest target, for example. Maybe I didn’t make it clear that I have multiple possible targets, such as enemies.


(goldentaiji) #4

Actually you can use that. If you’re python savvy in the blender game engine… You can change the object that the track to actuator tracks (setObject(‘object name’) I think). So you could possibly use a near sensor (to see what objects that you’re near, getHitObjectList()) and a track to operator with a few more lines of python code and you got what you need :smiley: . Yup, blender rocks.

Jason Lin


(Toomai) #5

So, you’re saying that I just locate the actuator and change the object name depending on a near sensor? Okay, I can understand that. The problem is, I don’t know how to use that knowledge in a script.