0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Can you share your .blend file? $\endgroup$ – p2or Dec 31 '14 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 '14 at 18:40
1
$\begingroup$

"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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ In the demo, the weapons track to objects that have the property "hit." $\endgroup$ – blackhole Jan 3 '15 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.