I’m using upbge 0.2.5b and I am trying to add breaking to the add physics constraint node. I am pretty new to python and all help is appreciated. My current code is:
import bpy
import bge_netlogic
NLParameterSocket = bge_netlogic.basicnodes.NLParameterSocket
NLParameterNode = bge_netlogic.basicnodes.NLParameterNode
NLIntegerFieldSocket = bge_netlogic.basicnodes.NLIntegerFieldSocket
class CustomPhysicsNode(bpy.types.Node, NLParameterNode):
bl_idname = "CustomPhysics"
bl_label = "Custom Physics Constraint"
def init(self, context):
NLActionNode.init(self, context)
self.inputs.new(NLConditionSocket.bl_idname, "Condition")
self.inputs.new(NLGameObjectSocket.bl_idname, "Target")
self.inputs.new(NLGameObjectSocket.bl_idname, "Child Object")
self.inputs.new(NLQuotedStringFieldSocket.bl_idname, 'Name')
self.inputs.new(NLConstraintTypeSocket.bl_idname, "")
self.inputs.new(NLBooleanSocket.bl_idname, 'Use World Space')
self.inputs.new(NLVec3FieldSocket.bl_idname, 'Pivot')
self.inputs.new(NLBooleanSocket.bl_idname, 'Limit Axis')
self.inputs.new(NLVec3FieldSocket.bl_idname, 'Axis Limits')
self.inputs.new(NLBooleanSocket.bl_idname, 'Linked Collision')
self.inputs.new(NLBooleanSocket.bl_idname, 'Use Breaking')
self.inputs.new(NLFloatFieldSocket.bl_idname, 'Breaking Power')
self.inputs[-1].value = True
self.outputs.new(NLConditionSocket.bl_idname, 'Done')
self.condition = None
self.target = None
self.child = None
self.name = None
self.constraint = None
self.use_world = None
self.pivot = None
self.use_limit = None
self.axis_limits = None
self.linked_col = None
self.use_breaking = None
self.breaking_power = None
self.done = None
self.OUT = LogicNetworkSubCell(self, self.get_done)
def get_done(self):
return self.done
def get_input_sockets_field_names(self):
return ["condition", "target", "child", "name", "constraint", 'use_world', "pivot", 'use_limit', "axis_limits", "linked_col", "use_breaking", "breaking_power"]
def get_output_socket_varnames(self):
return ["OUT"]
def evaluate(self):
self.done = False
condition = self.get_parameter_value(self.condition)
if not condition:
return
target = self.get_parameter_value(self.target)
if none_or_invalid(target):
return
child = self.get_parameter_value(self.child)
if none_or_invalid(child):
return
name = self.get_parameter_value(self.name)
if none_or_invalid(name):
return
constraint = self.get_parameter_value(self.constraint)
if none_or_invalid(constraint):
return
pivot = self.get_parameter_value(self.pivot)
if none_or_invalid(pivot):
return
use_limit = self.get_parameter_value(self.use_limit)
if none_or_invalid(use_limit):
return
use_world = self.get_parameter_value(self.use_world)
if none_or_invalid(use_world):
return
axis_limits = self.get_parameter_value(self.axis_limits)
if none_or_invalid(axis_limits):
return
linked_col = self.get_parameter_value(self.linked_col)
if none_or_invalid(linked_col):
return
self._set_ready()
flag = 0 if linked_col else 128
if use_world:
pivot.x -= target.localPosition.x
pivot.y -= target.localPosition.y
pivot.z -= target.localPosition.z
if use_limit:
target[name] = bge.constraints.createConstraint(
target.getPhysicsId(),
child.getPhysicsId(),
constraint,
pivot_x=pivot.x,
pivot_y=pivot.y,
pivot_z=pivot.z,
axis_x=axis_limits.x,
axis_y=axis_limits.y,
axis_z=axis_limits.z,
flag=flag
)
else:
target[name] = bge.constraints.createConstraint(
target.getPhysicsId(),
child.getPhysicsId(),
constraint,
pivot_x=pivot.x,
pivot_y=pivot.y,
pivot_z=pivot.z,
flag=flag
)
if use_breaking:
target[name].breakingThreshold = breaking_power
self.done = True
bge_netlogic.register_nodes("Objects", CustomPhysicsNode)
I am trying to modify the code I found in the netlogic folder, which was split between two files.