# Game engine firearm

I'm trying to set up physics through python, what I want is an object fired from an empty at every mouse click. My first problem is spawning an object (the bullet), my class asks for a gameObject which can't be a "bpy" data as I tried here, how can I tell python that I want to use this "Icosphere" object ? Same issue with the KX_SCA_AddObjectActuator, I need to provide the refered object. In this picture the click pops up a sphere but it creates two of them, one on pressure and one on relief, just as when following the answer. I want only on object created with a mouseclick.

Added a check for the sensor status (from this list): I think it speaks for itself.

Never ever use bpy within bge code.

• bpy is the Blender API (not available without Blender, will not effect running scenes)
• bge is the BGE API

An object can easily be created via:

copiedObject = addObject(originalObject, referenceObject, time=0)


The new object will inherit

• the mesh, physics and material data from originalObject
• the position, orientation, scale, velocities from the referenceObject

ReferenceObject needs to be inactive (at an hidden layer).

Both - originalObject and referenceObject - can be provided as name (string). If there is no such object with the given name, the call will fail. If there is more than one object with the same name, any of the found one will be used for copying.

example code, assuming you have "Empty" at layer 1 and "Icosphere" at layer 2 (hidden).

import bge

scene = bge.logic.getCurrentScene()