UPBGE - Python-created constraint disables other constraints

(Thatrius) #1

Hi,
I’m trying to create a script, where upon clicking the mouse, a Rigid Body Joint is created between a cube and whatever other objects are around it. The cube, though, already has an existing RBJ upon entering the game - which is completely messed up when another is added with Python.
Here’s the script I have so far:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
obj = bge.logic.getCurrentScene().objects
hit = cont.sensors['Collision']
click = cont.sensors["Mouse"]
		
if click.positive:
    for i in hit.hitObjectList:
        id1 = own.getPhysicsId()
        id2 = i.getPhysicsId()
        obj1['joint'] = bge.constraints.createConstraint(id1, id2,1,0,0,0)
        obj1['joint'].setParam(0, 0.0, 0.0) #No X translation
        obj1['joint'].setParam(1, 0.0, 0.0) #No Y translation
        obj1['joint'].setParam(2, 0.0, 0.0)

Upon running this script, all previous constraints start behaving very weirdly. They still work in a sense, but the RBJs become more of a weak force than an actual constraint - like an elastic spring or something.
Is this a common problem? It seems to work just fine in regular BGE…

(BluePrintRandom) #2

I will look into what has changed, in the meantime, try creating all the constraints in game as a work around.

(Thatrius) #3

I figured it out- or, I think I did. I replaced the 'obj1’s with just 'obj’s, that seemed to fix the problem. Not sure why, though. Maybe it’s just that ‘obj’ is one of the objects being assigned the constraint, and it doesn’t work otherwise…