Breakable Rigid Body Joints with Python?


(Thatrius) #1

Hi all,
I’m trying to make a Rigid Body Joint constraint that can be disrupted by outside forces and collisions.
For example, if I had a structure made of blocks, and pushed it over, only the blocks that underwent the most impact would break apart from the rest of the model - So basically, a realistic collapse.

But so far, I’m unsure as to how I could detect impact - or at least the velocity before impact - with the current sensors.

I’ve already looked at the Bullet Constraints addon (the one with the ‘breakable’ option for constraints); but it doesn’t seem to work with the Game Engine, so I’ve ruled it out as an option.

Is there a way to achieve this with BGE Python?
Thanks!


(billyzill) #2

use upbge 1.9 or greater:
https://doc.upbge.org/releases.php?id=0.1.9


(Thatrius) #3

Thanks! I installed upbge; and it seems to open my file from regular bge just fine.
However, nothing retained its texture or material… anything that had a texture or material is suddenly without shading, so its hard to make sense of anything. Can this be fixed?


(billyzill) #4

It sounds like your textures were setup in BI not GLSL mode. UPBGE works only with GLSL mode. You really don’t want to use BI anyway. There are also a few new options for GLSL mode in upbge that might be causing issues if BI is not the problem. I’d say retexture them inside UPBGE.


(Thatrius) #5

I just disabled an HDR texture (mapped by reflection) from everything; that seemed to do the trick. I did like that HDR, though. My textures were created in GLSL mode, so maybe the .hdr format just isn’t supported?


(Thatrius) #6

Just tried out the breakable constraints, though. Exactly what I needed, thanks! :slight_smile:


(Thatrius) #7

Also, is there a way to detect the Impact/Reaction Force with Python? I’d like to be able to trigger a script when the object hits something/breaks.
It would also be ideal to set a breakable constraint in-game. But while I can set a regular constraint, I’m not sure how to enable the ‘use_breaking’ tickbox from code…
Here’s what I have so far:

import bge
from bge import logic
from bge import constraints
cont = bge.logic.getCurrentController()
obj = bge.logic.getCurrentScene().objects
own = cont.owner
near = cont.sensors['Near']
constraint_type = 2

# get object list
objects = logic.getCurrentScene().objects

# use bottom right edge of Object1 for hinge position
edge_position_x = 0
edge_position_y = 0
edge_position_z = 0

# rotate the pivot z axis about 90 degrees
edge_angle_x = 0
edge_angle_y = 0
edge_angle_z = 0
# get object named Object1 and Object 2

for i in near.hitObjectList:
    object_1 = own
    object_2 = i
    physics_id_1 = object_1.getPhysicsId()
    physics_id_2 = object_2.getPhysicsId()
    constraints.createConstraint(physics_id_1, physics_id_2,
                                constraint_type,
                                edge_position_x, edge_position_y, edge_position_z,
                                edge_angle_x, edge_angle_y, edge_angle_z)
    bge.constraints.use_breaking
    bge.constraints.breaking_threshhold = 0

Thanks for all the help!