Carry a weapon off a shelf?


I have this example, I tried one from the site Youtube, it doesn’t really do what I want it to do, but thought I try some of the bricks out.

I just don’t understand the whole way of trying to carry a weapon. So as seen the weapon is on the shelf, so I want the character to be able to carry it. So how do I go about this?

I did edit the number values there, no change, it remains on the shelf.

I have also tried using an empty on the hand, added a name to the character game property that is, and changed the near brick for the gun to that name.

One would think there would be multiple tutorials on this…dating back a few years.


one way is to parent an empty where you want the weapon to be carried.
make a copy of the weapon and put it on an inactive layer.

When the character is near the weapon (several ways to do this) the weapon on the shelf ends with endObject.
And the weapon on the inactive layer is spawned to the empty parented to the character with edit object > add object.

Don’t forget parent the weapon on inactive layer to the empty. Always------and------Parent > set parent > Empty.

It fakes it, so to speak.

Well the key does remove the weapon on the shelf. How ever the weapon i have placed in another layer doesn’t appear.

I’m notsure what could be the reason for that, could it be the coordinate position of the axis?

I tried x, y, linear velocity setting there, nothing happens with that.


I can’t see that near sensor, Are you sure you are close enough to the gun on the shelf to turn the near sensor true? Also, is the gun on the shelf an actor? You’ll have to rotate the empty to get the gun aimed in the right direction. And if you have an armature on your character, you should bone parent the empty to the hand bone, or finger bone, whatever. So that the gun moves with the bone.

Holding - string
Time - integer

Keypress(pickup)---------python(see below)

if Time interval(min 1 max 100)---------and--------- -1 to property Time


import bge
cont = bge.logic.getCurrentController
own = cont.owner

Keypress = cont.sensors['Keypress']

if 'Hand' not in own: 
    for child in own.childreRecursive:
        if 'handTag' in  child
            own['Hand'] = child
        if 'headTag' in child:
            own['Head'] = child

#this code looks up a object parented to the actor with the property 'handTag'
# (your hand object) and your head object has the property 'headTag' 

if Keypress.positive and type(own['Hand']) is str and own['Time']==0:
    # if you press pickup weapon and time is zero and not holding weapon
    # cast ray
    rayEnd = own['Head'].worldPosition+own['Head'].worldOrientation.col[2]*-6
    rayStart = own['Head'].worldPosition
    Ray = own.rayCast(rayEnd,rayStart,0,'pickUpItem',0,0,0)
    # if ray hits pickup item pick it up
    if Ray[0]:
        HitObject= Ray[0]
        HitObject.worldPosition = own['Hand'].worldPosition
        HitObject.worldOrientation = own['Hand'].worldOrientation
        own['Hand']['Holding'] = HitObject
        own['Time'] = 30

this is the code to detect a pickup item and place it in your hand, facing the same way as the hand, and parent it to the hand, now own[‘Hand’][‘Holding’] is the weapon, so you can trigger weapon logic you setup in each weapon…

Yes the weapon the shelf does disappear when next to it, it just doesn’t load in the hand of the character. The Armature is very basic, it even looks odd when walking rapidly. I haven’t set it up with more bones for a natural quick movement. I’m not that bothered about that. I just want to get the functions of the mini game working.

I only want to use the bricks for this…Python is something I want to eventually try with blender. Thanks.

I have a couple of enemies that follow the player, upside down that is, so I’ll need to be able to shoot them.

I have made a start on the shooting, I used two video clips for this, one that has made it work, the other doesn’t work for it, but uses the projectile and not an empty.

With the empty it does work but on the edit brick, it doesn’t move beyond where it appears after being triggered by a key.


@BPR that script looks useful, I’m always interested in learning new tricks. I’ll check it out later. THX :slight_smile: I use a script with a ray that gets the hit object, and MMB, instead of Near. It’s a bit expensive to use though.

@ modling blender. So it is working? but won’t move with the armature animation? Is it bone parented? You have to select the armature, then go into pose mode, select the bone you want, then shift select the empty, the bone should be blue, then ctrl P > parent to the bone. This parents the empty to that specific bone. In pose mode, rotate the bone, the empty should move with the bone. You can then move the empty to fine tune it.

EDIT: @BPR. I tried your script, works great so far. Nice work. :slight_smile:

No it does work as the image displays, what doesn’t work is the bullet doesn’t move away it remains stuck there, and when ever fired. What couldbe causing that?

File - video soon (I get the script working)

if you like I can make a version where the weapon contains a trigger to fire logic,
bricks or python


WorkingWeaponPickUp_NoFire.blend (461 KB)

@ modelinblender If your using an object as a bullet, (instead of a ray) add object to spawn the bullet. Then the barrel of the gun, or whatever it is that spawns the bullet. has to be set to ghost. “No collision” or anything else, will hinder the bullet.

~ key = pick up

Left mouse = fire


WorkingWeaponPickUp_Fire.blend (484 KB)

I had used an object when I first made a shooter with a FP view, via another clip on the video site dated from last year.

I don’t see why an object isn’t a problem it worked for the other examples.

Spawn an object? I didn’t need that the first time around, spawn how exactly? The empty is used to get the weapon in the hand, the other empty which is the cross hairs version is for the fire mechanism.

So the bullet goes the direction I want it, it just remains stuck in the air.

Blue print Random, well I think the example I have used seems okay, just a bit of a hitch with the lack of physics that should be taking place.