Add in new object as a parent for weapon

This clip shows that the weaon doesn’t load into the scene, I have done since the clip, made sure the object is parented to the gun_spawn object that the player has.

So

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

equipped = own['equipped']
target = own['target']
timer = own['timer']
change = own['change']
reload = own['reload']
Grenades = own['Grenades']
Smoke = own['Smoke']
shoot = own['shoot']

collide = cont.sensors['cutscene']

#animations
down_m24 = cont.actuators['downm24']
downGlock = cont.actuators['downGlock']
upm24 = cont.actuators['pickupm24']
upGlock = cont.actuators['pickupGlock']
downGren = cont.actuators['down_Gren']
upGren = cont.actuators['pickup_Gren']
Sdown = cont.actuators['Sdown']
Sup = cont.actuators['Sup']
Kdown = cont.actuators['knifedown']
Kup = cont.actuators['knifeup']
opendoor = cont.actuators['opendoor']

self = scene.objects[own.name]
movement = scene.objects['player']

#sets change == True
if own['target'] != own['equipped'] and reload == False and shoot == True or own['equipped'] == 0 or own['target'] == 6:
    self['change'] = True
elif own['target'] == own['equipped']:
    self['change'] = False

#timer  
if change == True and timer < 30 and movement['door'] == False:
    own['timer'] += 1

if change == True and movement['door'] == True and timer < 45:
    own['timer'] += 1
    
#putting down weapon
if equipped == 0 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 1 and change == True and timer == 0:
    cont.activate(down_m24)
if equipped == 2 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 3 and change == True and timer == 0:
    cont.activate(downGren)
if equipped == 4 and change == True and timer == 0:
    cont.activate(Sdown)
if equipped == 5 and change == True and timer == 0:
    cont.activate(Kdown)
if equipped == 7 and change == True and timer == 0:
    cont.activate(Kdown)
    
#ends old weapon + animation
if timer == 15 and change == True and equipped == 0:
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 1:
    own.sendMessage("endm24")
    cont.deactivate(down_m24)
if timer == 15 and change == True and equipped == 2:
    own.sendMessage("endglock")
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 3:
    own.sendMessage("endGren")
    cont.deactivate(downGren)
if timer == 15 and change == True and equipped == 4:
    own.sendMessage("endSmoke")
    cont.deactivate(Sdown)
if timer == 15 and change == True and equipped == 5:
    own.sendMessage("endKnife")
    cont.deactivate(Kdown)
if timer == 15 and change == True and equipped == 7:
    own.sendMessage("endchain")
    cont.deactivate(Kdown)
    
#spawn new weapon
if timer == 15 and change == True and target == 1:
    scene.addObject('m24', own, 0)
if timer == 15 and change == True and target == 2:
    scene.addObject('Glock', own, 0)
if timer == 15 and change == True and target == 3:
    scene.addObject('Grenade', own, 0)
if timer == 15 and change == True and target == 4:
    scene.addObject('smoke', own, 0)
if timer == 15 and change == True and target == 5:
    scene.addObject('knife', own, 0)
if timer == 15 and change == True and target == 7:
    scene.addObject('chain', own, 0)

#picking up weapon
if timer > 15 and timer < 30 and change == True and target == 1:
    cont.activate(upm24)
if timer > 15 and timer < 30 and change == True and target == 2:
    cont.activate(upGlock)  
if timer > 15 and timer < 30 and change == True and target == 3:
    cont.activate(upGren)
if timer > 15 and timer < 30 and change == True and target == 4:
    cont.activate(Sup)
if timer > 15 and timer < 30 and change == True and target == 5:
    cont.activate(Kup)
if timer > 15 and timer < 30 and change == True and target == 7:
    cont.activate(Kup)
if timer > 15 and timer < 45 and change == True and movement['door'] == True and target == 6:
    cont.activate(opendoor)

#open sesame
doorsound = cont.actuators['doorsound']
if timer == 30 and change == True and movement['door'] == True and target == 6:
    select = collide.hitObjectList[0]
    own.sendMessage("opendoor", "", str(select))
    cont.activate(doorsound)
#resetting properties
if timer == 30 and change == True and own['equipped'] != own['target'] and movement['door'] == False:
    own['equipped'] = own['target']
    own['timer'] -= 31
    cont.deactivate(upm24)
    cont.deactivate(upGren)
    cont.deactivate(upGlock)
    cont.deactivate(Sup)
    cont.deactivate(Kup)

#resetting after cutscene
if timer == 45 and change == True and movement['door'] == True and own['equipped'] != 6:
    own['equipped'] = own['target']
    movement['door'] = False
    movement['control'] = True
    movement['cutscene'] = 0
    self['timer'] = 0
    own.sendMessage("restorecontrol")
    cont.deactivate(opendoor)
    own['target'] = 2
    
#intial weapon selection
if equipped == 0:
    self['target'] = 2

Press 7 and only a blank hand rig is shown below the camera as the clip shows, no object. The object is not aligned the same as the others in the other layer it is in, but that shouldn’t matter, so long as it faces the same way as all, and is parented it should work.

Is there some sort of difference that may affect why the object doesn’t spawn in, so chain object should spawn

Should be okay?

If i moved the object up there, it would just, move to the top in the level layer, if I moved it. So that isn’t any good. I did try the tutorials for guidance on the fps series, but I think I’ve done what I can do. All the key points are done for it to load in, and parented.

Thanks

I decieded to try an name the new item as one of the existing items, and that didn’t change anything. So Grenade was removed and I just named the object that. So the Grenade code should load the item from the second layer instead of the old original object.

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

equipped = own['equipped']
target = own['target']
timer = own['timer']
change = own['change']
reload = own['reload']
Grenades = own['Grenades']
Smoke = own['Smoke']
shoot = own['shoot']

collide = cont.sensors['cutscene']

#animations
down_m24 = cont.actuators['downm24']
downGlock = cont.actuators['downGlock']
upm24 = cont.actuators['pickupm24']
upGlock = cont.actuators['pickupGlock']
downGren = cont.actuators['down_Gren']
upGren = cont.actuators['pickup_Gren']
Sdown = cont.actuators['Sdown']
Sup = cont.actuators['Sup']
Kdown = cont.actuators['knifedown']
Kup = cont.actuators['knifeup']
opendoor = cont.actuators['opendoor']

self = scene.objects[own.name]
movement = scene.objects['player']

#sets change == True
if own['target'] != own['equipped'] and reload == False and shoot == True or own['equipped'] == 0 or own['target'] == 6:
    self['change'] = True
elif own['target'] == own['equipped']:
    self['change'] = False

#timer  
if change == True and timer < 30 and movement['door'] == False:
    own['timer'] += 1

if change == True and movement['door'] == True and timer < 45:
    own['timer'] += 1
    
#putting down weapon
if equipped == 0 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 1 and change == True and timer == 0:
    cont.activate(down_m24)
if equipped == 2 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 3 and change == True and timer == 0:
    cont.activate(downGren)
if equipped == 4 and change == True and timer == 0:
    cont.activate(Sdown)
if equipped == 5 and change == True and timer == 0:
    cont.activate(Kdown)
    
#ends old weapon + animation
if timer == 15 and change == True and equipped == 0:
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 1:
    own.sendMessage("endm24")
    cont.deactivate(down_m24)
if timer == 15 and change == True and equipped == 2:
    own.sendMessage("endglock")
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 3:
    own.sendMessage("endGren")
    cont.deactivate(downGren)
if timer == 15 and change == True and equipped == 4:
    own.sendMessage("endSmoke")
    cont.deactivate(Sdown)
if timer == 15 and change == True and equipped == 5:
    own.sendMessage("endKnife")
    cont.deactivate(Kdown)
    
#spawn new weapon
if timer == 15 and change == True and target == 1:
    scene.addObject('m24', own, 0)
if timer == 15 and change == True and target == 2:
    scene.addObject('Glock', own, 0)
if timer == 15 and change == True and target == 3:
    scene.addObject('Grenade', own, 0)
if timer == 15 and change == True and target == 4:
    scene.addObject('smoke', own, 0)
if timer == 15 and change == True and target == 5:
    scene.addObject('knife', own, 0)


#picking up weapon
if timer > 15 and timer < 30 and change == True and target == 1:
    cont.activate(upm24)
if timer > 15 and timer < 30 and change == True and target == 2:
    cont.activate(upGlock)  
if timer > 15 and timer < 30 and change == True and target == 3:
    cont.activate(upGren)
if timer > 15 and timer < 30 and change == True and target == 4:
    cont.activate(Sup)
if timer > 15 and timer < 30 and change == True and target == 5:
    cont.activate(Kup)
if timer > 15 and timer < 45 and change == True and movement['door'] == True and target == 6:
    cont.activate(opendoor)

#open sesame
doorsound = cont.actuators['doorsound']
if timer == 30 and change == True and movement['door'] == True and target == 6:
    select = collide.hitObjectList[0]
    own.sendMessage("opendoor", "", str(select))
    cont.activate(doorsound)
#resetting properties
if timer == 30 and change == True and own['equipped'] != own['target'] and movement['door'] == False:
    own['equipped'] = own['target']
    own['timer'] -= 31
    cont.deactivate(upm24)
    cont.deactivate(upGren)
    cont.deactivate(upGlock)
    cont.deactivate(Sup)
    cont.deactivate(Kup)

#resetting after cutscene
if timer == 45 and change == True and movement['door'] == True and own['equipped'] != 6:
    own['equipped'] = own['target']
    movement['door'] = False
    movement['control'] = True
    movement['cutscene'] = 0
    self['timer'] = 0
    own.sendMessage("restorecontrol")
    cont.deactivate(opendoor)
    own['target'] = 2
    
#intial weapon selection
if equipped == 0:
    self['target'] = 2
grenade script
import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]
movement = scene.objects['player']

Grenades = own['Grenades']
Smoke = own['Smoke']
timer = own['timer']
equipped = own['equipped']
reload = own['reload']
change = own['change']

#automatic fire
auto = cont.sensors['auto']

#single fire
single = cont.sensors['single']

throw = cont.actuators['Throw_Gren']
up = cont.actuators['pickup_Gren']
Sthrow = cont.actuators['Sthrow']
Sup = cont.actuators['Sup']

#add grenades
addGren = cont.actuators['Gren']
addSmoke = cont.actuators['Smoke']

#smoke grenade

if single.positive == True and Smoke >= 1 and equipped == 4 and reload == False and change == False and timer == 0 and movement['control'] == True:
    own['Smoke'] -= 1
    own.sendMessage("Smoke_Anim")
    cont.activate(Sthrow)
    self['reload'] = True

if equipped == 4 and timer < 76 and reload == True:
    own['timer'] += 1

if equipped == 4 and timer == 41 and reload == True:
    own.sendMessage("endSmoke")
    cont.activate(addSmoke)
    
if equipped == 4  and timer == 61 and reload == True and Smoke >= 1:
    scene.addObject("smoke", own, 0)
    cont.deactivate(Sthrow)
    
if equipped == 4 and timer > 61 and timer < 76 and reload == True and Smoke >= 1:
    cont.activate(Sup)

if equipped == 4 and timer == 76 and reload == True and Smoke >= 1:
    self['reload'] = False
    self['timer'] = 0
    
elif equipped == 4 and timer == 61 and reload == True and Smoke <= 0:
    self['reload'] = False
    self['timer'] = 0
    self['target'] = 1    

    
#frag grenade

if single.positive == True and Grenades >= 1 and equipped == 3 and reload == False and change == False and timer == 0 and movement['control'] == True:
    own['Grenades'] -= 1
    own.sendMessage("Gren_Anim")
    cont.activate(throw)
    self['reload'] = True
    
if equipped == 3 and timer < 76 and reload == True:
    own['timer'] += 1

if equipped == 3 and timer == 41 and reload == True:
    own.sendMessage("endGren")
    cont.activate(addGren)

if equipped == 3 and timer == 61 and reload == True and Grenades >= 1:
    scene.addObject("Grenade", own, 0)
    cont.deactivate(throw)
    
if equipped == 3 and timer > 61 and timer < 76 and reload == True and Grenades >= 1:
    cont.activate(up)
    
if equipped == 3 and timer == 76 and reload == True and Grenades >= 1:
    self['reload'] = False
    self['timer'] = 0
    
elif equipped == 3 and timer == 61 and reload == True and Grenades <= 0:
    self['reload'] = False
    self['timer'] = 0
    self['target'] = 1    

#auto grenade throw

Gkey = cont.sensors['G']

#with m24 + glock equipped

if equipped == 1 and Gkey.positive and timer == 0 and reload == False and change == False and Grenades >= 1 and movement['control'] == True:
    self['target'] = 3
if equipped == 2 and Gkey.positive and timer == 0 and reload == False and change == False and Grenades >= 1 and movement['control'] == True:
    self['target'] = 3

if equipped == 1 and Gkey.positive and timer == 0 and reload == False and change == False and Grenades == 0 and Smoke >= 1 and movement['control'] == True:
    self['target'] = 4
if equipped == 2 and Gkey.positive and timer == 0 and reload == False and change == False and Grenades == 0 and Smoke >= 1 and movement['control'] == True:
    self['target'] = 4



Grenades python code.

That shouldn’t matter about this, the object is added

Hi,
after your pm’s I took the time for this Horror :slight_smile:
I used my last corrected version from this thread:

and made the chainsaw work on keypress 7.
What did I do?

  1. unparented the “chain” from “gun spawn”
  2. renamed “chain” to “chain_obj”, created an empty called “chain” at the origin of “chain_obj” and parented “chain_obj” to " chain". (This is only for easier changing the rotation and position of the chain because it uses the same animation as knife and it would be impossible to make adjustments wihthout having to use a new animation.)
  3. moved the logic bricks from “chain_obj” to “chain” and changed the message from “endChain” to “endchain” because that matters for the python in Changed.py
  4. looked how the logic bricks are for the “knife” (key 5) and built the exact same for key “7”.
  5. tested it: set the collision of the child obj of "“chain_obj” (the real chain of the chainsaw) to no collision. This has a cool animation for the chain, changed that from keyinput “O” to left mouise button.
  6. adjusted the position of the “chain_obj” in relation to the empty “chain” so it is corret when spawned.

Didn’t have to make any alterations to any python script as you already made a correct entry for the key 7 in “changed.py”. Hoorray!

Now in game when pressing 7 you get the chainsaw and on left mouse click the chain rolls. It will make the same damage as the knife.
No sound or other cool animations.

Okay that works fine. What is the next step for an effect? So knife code is fine? Use the default enemy after some contact the AI is removed, similar to the knife, I guess.

I then will want to see what is possible for the AI object, can an object be removed, so two objects load in once the AI has been removed, or some an arm falling off of the AI, and the Ai left there something. Obviously it is known the AI only blocks the player, so with my example file I have, the small areas are not good for the player, they only trap the player with the AI.

But yes, what can you suggest for the existing ai.

If you are using the default enemies with their python codes “AIhealth.py” (the enemies down in the subway) or the python code “AIhealth2.py” (the enemy on the stairs) you can easily set them to nocollision (=ghost) by adding a single line at the right places.
Add this line
own.suspendDynamics(True)
under each line that either reads
cont.activate(headdeath)
or
cont.activate(bodydeath)
or
cont.activate(crouchdeath)

For the enemy on the stairs the “AIhealth2.py” is this:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

health = own['health']

#knife
bknife = cont.sensors['bknife']

#bullet hit
bodyhit = cont.sensors['bodyhit']
headhit = cont.sensors['headhit']

#death states
headdeath = cont.actuators['State2']
bodydeath = cont.actuators['State3']


#knife states
if bknife.positive and health > 1:
    own['health'] -= 1
   
if bknife.positive and health == 1:
    cont.activate(bodydeath)

#headshot
if headhit.positive:
    cont.activate(headdeath)

#bodyshot
if bodyhit.positive and health > 1:
    own['health'] -= 1
    
if bodyhit.positive and health == 1:
    cont.activate(bodydeath)

Guess how the edited code looks like?

I tried getting the objects in, but it doesn’t work for the player to go through the door. The walls I added in.

I even tried scaling the door so it is longer, but the door just goes to its default position once opened. I don’t know what the difference is between the player I have and the one from the older file.

It’s better to solve one problem after the other.
So for the code above to get the enemies be non-colliding after death:
The added line
own.suspendDynamics(True)
must be aligned exactly with the upper line because it needs to be part of the if -statement.

if bodyhit.positive and health == 1:
    cont.activate(bodydeath)
    own.suspendDynamics(True)

ONLY add this line after
cont.activate(headdeath)
or
cont.activate(bodydeath)
or
cont.activate(crouchdeath)

Remove the code from line 48.
Delete the ‘p’ in line 54.

Not doing this breaks the whole code and enemy behaviour

Here is the demo-Level with the code applied to both AIHealth.py’s so the enemies don’t block the player after death.
I also put in the skeleton of your mentioned blendswap

But I didn’t use that but the simplified version mentioned in the comments there.
Still very high-poly. Removed subdivision-modifier and the rig and all the vertex-groups as this stuff made the engine come to an halt. 1 fps
So you can try to apply the armature of the enemies to use the animations. I tried it but this is too much work for me. So now the skeleton only stands there.

Can I append the skeleton?

as for the corridors I had setup, I don’t know what was the difference between the file you made and mine, the newer ones that had the doors and walls, and the player could fit through.

But that gave it a challenge, where as it is, it is open, but my original idea had no walls or doors, the only option is not to use doors, only the walls and make the gap a bit wider for the player.

It was only a new item, and some new AI, which failed, so the existing AI or use the new AI if that functions okay, with a basic animated movement for it. Hmm

So I tried my best to apply the existing enemy armature to the skeleton mesh.
Was new for me but learnt a lot. I also left an unmodified Skeleton in there in neutral pose in case somebody wants to use it for other purposes or armatures. Thanx for your ideas!
Looks quite spooky :ghost:


It does look spooky, just what I had thought five months ago, very good. :slightly_smiling_face:

My inspiriation was from Doom 3, released in 2004 on PC and then the Xbox in 2005, I played both versions, but only completed the xbox copy, I have it even now. The chainsaw was the idea from that game.

Hmm. But yes, the doors and corridor walls I have, they make it more challenging. Otherwise, I don’t know how you make that space more challenging for the player, unless you just have random AI loading in, and the player has to remove them all as the challenge. Or has to escape the area.

What may changed between the player and the player from the older file, which now became the newest file.

Would like to try and keep some of these objects. I scaled them, and apply scale, so it is the solution. The animation kind of lowers the door a little from it’s original location, but it is better than nothing, for closing them, if wanted.

Hmm, I just transferred some of the corridor parts, so I will just have to edit it in the new but older file, but the new file now it is.

Hmm, it is a bit slow with another AI added in. So three or four in the area, i noticed the objects I appended, one moves so the player can’t really get through a corridor, and one object is missing. This happened the other day.

The video previews my test

The object there is in the game attached to the cube. The other AI is present, and then a few more AI are around. Slows down. I did remove a modified, and joined the object, after having duplicated. So since my own AI failed, I thought I’d see what I can do.

Good catch
I had a similar problem:
When I’m very close to the skeleton suddenly the frames dropped down to 1.
Fortunately this fixed it:
Set the physics of the skeleton mesh to “no collision” instead of only “static with ghost”

You can also fix something in the materials tab: for the “skull” material enable “Backface culling”:

I hope it works for your problem too.

I guess.

I noticed that is object floats through the objects of the level. I tried making the level section static, and ghost. Currently it is no collision.

The cube is static.

Parented objects don’t follow collision physics. They can detect collisions though if one of the colliding objects is of a physic type of Dynamic or RigidBody however.