BGE proposal - Add a method to detect constraints applied on start.

if someone want make some test:

import bge




def create_constraint(ob1, ob2, numb=12, pos=[0,0,0], rot=[0,0,0], coll=False):
    for o in [ob1, ob2]:
        assert isinstance(o, bge.types.KX_GameObject) 
        assert hasattr(o, "meshes")
    
    p1, p2 = [o.getPhysicsId() for o in [ob1, ob2]]

    assert numb in {1,2,3,4,12}
    
    for i in range(3):
        pos[i] = float(pos[i])
        rot[i] = float(rot[i])
        
    coll = 64 if coll else 128
     
    
    
    constraint = bge.constraints.createConstraint(p1, p2, numb, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2], coll) 
    pid = constraint.constraint_id
    return constraint
    

#########


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




ob1 = scene.objects["B"]
ob2 = scene.objects["A"]
cs = create_constraint(ob1, ob2, 12, pos=[0,0,0],rot=[0,0,0], coll=False)


cs.setParam(1,-1,1)
cs.setParam(2,-1,1)
cs.setParam(3,-1,1)


print(dir(cs))



astract module :slight_smile:



import bge

_constraints = []



class Constraint:
    def __init__(self, ob1, ob2, numb=12, pos=[0,0,0], rot=[0,0,0], coll=False):
        for o in [ob1, ob2]:
            assert isinstance(o, bge.types.KX_GameObject) 
            assert hasattr(o, "meshes")
        
        p1, p2 = [o.getPhysicsId() for o in [ob1, ob2]]


        assert numb in {1,2,3,4,12}
        
        for i in range(3):
            pos[i] = float(pos[i])
            rot[i] = float(rot[i])
            
        coll = 64 if coll else 128
        
        constraint = bge.constraints.createConstraint(p1, p2, numb, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2], coll) 


        self._constraint = constraint
        self.owner = ob1
        self.target = ob2
        
    @property
    def invalid(self):
        return self._constraint.invalid
        
    def set_param(self, axis,mn=0,mx=0):
        self._constraint.setParam(axis, mn, mx)
        
    def get_param(self, axis):
        return self._constraint.getParam(axis)
        
        





def create_constraint(ob1, ob2, numb=12, pos=[0,0,0], rot=[0,0,0], coll=False):
    constraint = Constraint(ob1, ob2, numb, pos, rot, coll)
    _constraints.append(constraint)
        
        
def _validate_constraints():
    for i in [i for i in _constraints if i.invalid]:
        cs_id = i.constraint_id # not remember the code to write
        _constraints.remove(i)
    
    
def get_constraints(gob):
    _validate_constraints()
    return [i for i in _constraints if i.owner is gob]
    



can be ??

This is a wrapper. It would allow a cleaner way of creating constraints but it does not help regarding the proposed search operations.

i know but one time founded need something to manage it.

afaik change target or pivot(position, rotation or collision) require a new constraint

toretically the wrapper can do this