ccd projectile motion manager

here is a callback for ccd physics raycasts for projectile motion of rigid bodies or dynamic objects.

Attachments

ccd_physics_bullet_W_callback.blend (516 KB)

Hey, thanks for making this! I have some questions:
What are popList and multi_delete() for?
I would guess it deletes from the list?

yeah all at once, at the end, so it does not mess with the index

So for example when my bullet hits, it deletes itself, and I call multi_delete() to delete that bullet from the list?

the manager handles this already, just have the bullet delete itself and the manager removes itself

I have been thinking of using a dictionary instead of a list though and del instead of pop to make it o(n) instead of o*(n)

edit:
this should be much faster :smiley:


#manager






        
def BulletSystem():
    import bge
    manager = bge.logic.getCurrentScene().objects['Bullet_Manager']
    
    popList = []
    index=0
    keys = []
    for key in manager['Bullets']:
        bullet = manager['Bullets'][key]
        if not bullet.invalid:
            if 'Stick' not in bullet:
                    if 'Seek' in bullet:
                        bullet.alignAxisToVect(bullet.worldLinearVelocity,1,.5)
                        
                    if 'No_Gravity' in bullet:
                        
                        bullet.applyForce((0,0,bullet.mass*9.8),0)
                        
                    end = bullet.worldPosition+(bullet.worldLinearVelocity*.05)
                    start = bullet.worldPosition
                    if 'Debug' in bullet:
                        bge.render.drawLine(end,start,(1,1,1))
                    ray = bullet.rayCast(end,start,0,'',0,0,0)
                    if ray[0]:
                        if 'Health' in ray[0]:
                            ray[0]['Health']-=bullet['Damage']
                        local = ray[1]-ray[0].worldPosition
                        if ray[0].mass:
                            ray[0].applyImpulse(ray[1],bullet.worldOrientation.col[1]*bullet.worldLinearVelocity.magnitude*.1)
                            
                        if 'Sticky' in bullet:
                            bullet['Stick'] = ray[0].worldOrientation.inverted()*local
                            bullet['Target']=ray[0]
                        else:
                            keys.append(key)
                                
            else:
                bullet.worldPosition = bullet['Target'].worldTransform*bullet['Stick']
                bullet.setParent(bullet['Target'])
                keys.append(key)
        else:
            keys.append(key)
                
        
            
    if len(keys)>0:
        for keyz in keys:
            del manager['Bullets'][keyz]
                   
                
                
    


def main():
    import bge
    own = bge.logic.getCurrentController().owner


    cont = bge.logic.getCurrentController()
    own = cont.owner
    print('Created bullet system')
    own['Bullets']={}
    
    own.scene.pre_draw.append(BulletSystem)
    
main()




#add bullet
import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    manager =  own.scene.objects['Bullet_Manager']
    delay = cont.sensors['Delay']
    if delay.positive:
        
        added = own.scene.addObject('Bullet',own,0)
        added.applyForce((0,6200,0),1)
        added.applyForce((0,0,9.8*added.mass),0)
        name = added.name+"_" +str(manager['bullets'])
        manager['bullets']+=.0001
        added.name = name
        manager['Bullets'].update({added.name:added})
        #print('added')
        added['Damage']=10   
        if own['Debug']==True:
            added['Debug']=True
        added['Sticky']=True
        if own['Seek']==True:
            added['Seek']=True
        if own['Gravity']==False:
            added['No_Gravity']=True


main()



Attachments

ccd_physics_bullet_W_callback_optimized.blend (529 KB)

Now the gun registers the bullet in a que and the que adds the bullet after the physics step and the constraints are applied, so agents shooting weapons parented to armature actors bones that are using constraints :smiley:

[this solves several old bugs]

Attachments

Omin_weapon_V_4.blend (613 KB)

edited:

Attachments

Omni_weapon_V_4B.blend (764 KB)