I have previously asked a question on how to have a bullet hit the center of the screen, and I received a .blend. It confused me a little bit, as it included python and I am not familiar with python. The code reads:

import bge

controllor = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()

target = scene.objects['target']
ray = controllor.sensors['Ray']

if (ray.hitObject and not 'bullet' in ray.hitObject):
    target.worldPosition = ray.hitPosition

Does this mean the bullet has to always be called "bullet," I have multiple weapons, and multiple bullet shapes, speeds, damages, etc. Would I need to duplicate this script for every bullet type? Would I add commas to the script and show other bullet names? How would I let this script work for all my weapons?

  • $\begingroup$ Can you share your .blend file? $\endgroup$
    – p2or
    Dec 31, 2014 at 12:17
  • $\begingroup$ I'm sorry, i'm in a rush right now, but I have asked a question and the answer includes a .blend file. Just maybe add a second type of bullet when you hit "h" instead of space. $\endgroup$
    – blackhole
    Dec 31, 2014 at 18:40

1 Answer 1


"bullet" is a property that you should put on all your projectiles, that way your weapons will not track to the projectiles being added. all of your projectiles should have this property, only because the weapons behave very odd when they track to the bullets being fired. "target" is the name of the object that that the guns track to.

It essentially works like this:

The object "camera" sends out a ray from the ray sensor. if the ray collides with anything that does not have the property named "bullet", the object "target" will snap to the position where the ray collided. And because your guns are always tracking to the object "target" it will appear, and function as if the guns are always pointing to the center of the screen, wherever the object "camera" is looking.

  • $\begingroup$ In the demo, the weapons track to objects that have the property "hit." $\endgroup$
    – blackhole
    Jan 3, 2015 at 8:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .