Player flys away once weapon fired at AI at close contact (physics) problem I would guess

In this video, the AI used when firing the weapon, sends the player away. :neutral_face:

If you’re spawning a physical bullet, I suspect the bullet’s physics is causing an implode of collision bounds/physics. Set the bullet physics to type Static, with the “Ghost” option enabled.

Yep, looks like the bullet is intersecting with the player model. Try moving the bullet spawn point away from the player more, or use the ghost option like RPaladin mentioned.

This is the bullet?

The alternative is python code, where some of the mechanics of the game are, if not most. I am not sure where to find the bullet.

Shoot.py

import bge

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

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

#properties
m24ammo = own['m24_ammo']
glockammo = own['glock_ammo']
recoil = own['recoil']
equipped = own['equipped']
reload = own['reload']
change = own['change']
ADS = own['ADS']
shoot = own['shoot']
#automatic fire
auto = cont.sensors['auto']

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

#sounds
m24shot = cont.actuators['m24_fire']
glockshot = cont.actuators['glock_fire']

#animations

Rm24 = cont.actuators['m24recoil']
adsrecoil = cont.actuators['adsrecoil']
Rglock = cont.actuators['Glockrecoil']
adsGrecoil = cont.actuators['adsGrecoil']

#glockfire

if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 0 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(Rglock)
    cont.deactivate(Rglock)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)
if single.positive == True and glockammo >= 1 and equipped == 2 and reload == False and change == False and ADS == 2 and movement['control'] == True and shoot == True:
    own['glock_ammo'] -= 1
    cont.activate(adsGrecoil)
    cont.deactivate(adsGrecoil)
    own.sendMessage("4")
    own.sendMessage("glockflare")
    cont.activate(glockshot)
    cont.deactivate(glockshot)

if single.positive == True and reload == True and equipped == 2 or single.positive == True and change == True and equipped == 2:
    cont.deactivate(Rglock)

if single.positive == False and equipped == 2:
    cont.deactivate(adsGrecoil)

#m24 fire   
if auto.positive == True and m24ammo >= 1 and recoil >= 0 and recoil <= 3 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("1")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == True and m24ammo >= 1 and recoil >= 3 and recoil <= 6 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("2")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)
    
if auto.positive == True and m24ammo >= 1 and recoil == 7 and equipped == 1 and reload == False and change == False and ADS == 0 and movement['control'] == True:
    cont.activate(Rm24)
    cont.deactivate(Rm24)
    own['m24_ammo'] -= 1
    own.sendMessage("3")
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

    
if auto.positive == True and reload == True and equipped == 1 or auto.positive == True and change == True and equipped == 1:
    cont.deactivate(Rm24)
    cont.deactivate(adsrecoil)
    
if auto.positive == False and equipped == 1 or reload == True and equipped == 1 or change == True and equipped == 1 or movement['control'] == False:
    self['recoil'] = 0

#ads recoil   
if auto.positive == True and m24ammo >= 1 and recoil >= 0 and recoil <= 3 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("1")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == True and m24ammo >= 1 and recoil >= 3 and recoil <= 6 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("2")
    own['recoil'] += 1
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)
    
if auto.positive == True and m24ammo >= 1 and recoil == 7 and equipped == 1 and reload == False and change == False and ADS == 2 and movement['control'] == True:
    cont.activate(adsrecoil)
    cont.deactivate(adsrecoil)
    own['m24_ammo'] -= 1
    own.sendMessage("3")
    own.sendMessage("m24flare")
    cont.activate(m24shot)
    cont.deactivate(m24shot)

if auto.positive == False and equipped == 1:
    cont.deactivate(adsrecoil)

And bullethit.py

##############################################################
#Blender 2.5 bullethole script
 
#this script is free to use and is under no license agreement.
 
##############################################################
 
from bge import logic as GameLogic
from mathutils import Vector
c = GameLogic.getCurrentController()
own = c.owner
         
space = 0.003
         
# sensors
ray = c.sensors["Ray"]
ray2 = c.sensors['blood']
knife = c.sensors['knife']
m24 = c.sensors['m24']
glock = c.sensors['glock']
single = c.sensors['single']
timer = c.sensors['timer']

# actuator
spawn = c.actuators["spawns"]
spawn2 = c.actuators['spawnb']

#groundhit      
if ray.positive and m24.positive or ray.positive and glock.positive:
 # Get info
  pos_vec = Vector(ray.hitPosition)
  normal_vec = Vector(ray.hitNormal)
         
 # make object
  spawn.instantAddObject()
  bullet_hole = spawn.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz


#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
  
  
#knifehit
if knife.positive and single.positive and timer.positive == True:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("knife","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

There is no physical bullet, that was what I had thought when the mentioning about physics. There is only the above, and bloodmist texture in another layer.

from bge import logic
import random
import bge

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

if own['blood'] > 0:
    own['blood'] -= 1
    own.applyRotation([0.0, 0.0, (random.randint(0, 90))])
    scene.addObject("blood splat", own, 10)

if own['blood'] == 1 or own['blood'] == 2:
    scene.addObject("bloodmist", own, 30)

I don’t know. Is the objects there need to be one or more a static?

I don’t know where the bullet is, I may need it for an object to collide with so an object changes, without a bullet it may not work, at least not a physical one.

I can’t apply the message brick program.

Perhaps add a bullet for the collision object?

Make it a ghost, and it only fires from the gun that the object can collide with, and causes a change in event?

I don’t if I add the bullet to here or in the layer with the gun on the empty parented to that. And just add the object in from the same layer or what ever for the bullet. Should be okay. Code has a bullet, and then a physical one firing but only affects one object in the game.

I added the bullet effect, doesn’t work very well.

I saw this via the tutorial, it had a link to another older tutorial to do with guns, bullets,

from bge import logic
cont = logic.getCurrentController()
own = cont.owner
Rounds = 10

Fire = cont.sensors['Fire']
Reload = cont.sensors['Reload']
Ray = cont.sensors['Ray']


Ammo = own['Ammo']
Clips = own['Clips']

if 'init' not in own:
    own['init'] = 1
    own['Ammo'] = Rounds

if Ray.positive:
    logic.getCurrentScene().objects['Aim'].worldPosition = Ray.hitPosition

if Fire.positive:
    if Ammo > 0 and Fire.positive:
       own['Ammo'] -= 1
       logic.getCurrentScene().addObject('Bullet', "Aim",1)
            
    elif Clips > 0 and Fire.positive:
        own['Ammo'] = Rounds
        own['Clips'] -= 1
        
if Reload.positive:
     if Clips > 0:
         own['Ammo'] = Rounds
         own['Clips'] -= 1
     else:
         # Display "Out of ammo"
         pass       `Preformatted text`

Not sure if any of that could be useful

if Fire.positive:
if Ammo > 0 and Fire.positive:
own[‘glock’] -= 1
logic.getCurrentScene().addObject(‘Bullet’)

I don’t know, the bullet object being added in using code instead of the bricks.

Could the shoot.py contain the following bricks as my image shows?

The bullet the tutorial displays is the same process as what I did with my old game files, you have a object always moving in another layer.

So since there is no physical bullet, the one I have just flys to the right of the player along with the code bullet or what ever working as normal.

Thanks

I did remove the message and kept as it is, no change. The bullet is named bullet as a property.