bge addGroup() ?

Does such a function exist?

Like the addObject() function, I’m looking for a way to add groups. I have to objects grouped together on a different layer. These have a Rigid Body Joint Constraint applied to them and addObject() function does not (seem to) let me keep this constraint.

Maybe there is another way of achieving this? I could not find an addObject() function although I’m not great at navigating the bge api.

Thanks for any help.

EDIT

As Monster has pointed out there is no groups in the bge, however as he also points out I can spawn an object and use Python to set up the rigid body joints. After a bit of trial and error I was able to get the settings more or less how I like them.

This webpage was helpfull. The creator includes an example blend to experiment with.

http://bgepython.tutorialsforblender3d.com/PhysicsConstraints/LineHinge/createConstraint

For Limiting the rotation you need to use the setParam() function.

http://bgepython.tutorialsforblender3d.com/PhysicsConstraints/6DOF/RotatingMotor/setParam

The example above is with the constraint type 12, but it also works with constraint type 2. Axis rotation is described with radians (something I had to find out about).

There are no groups in the bge. You can add instantiating objects (objects with doupligroup enabled). As far as I remember rigid body joints need to be set up via Python as the are not established on instances. This might have been changed.

Thanks Monster, any idea where I might find out about setting up rigid body joints in python?

I would start with the API.

http://www.blender.org/documentation/blender_python_api_2_69_1/bge.constraints.html?#module-bge.constraints

The sample at the top is pretty good. Start with that and then let us know if you have questions.

Aah thanks, I keep forgeting to check the API!

That example seems pretty fully fleshed out, yeah, but there’s no reason to use the magic number 2 for the constraint_type variable. You should be able to use the constraints.LINEHINGE_CONSTRAINT constant.

Ok, so I more or less have my Rag Doll set up.

How do I limit the rotation?

(Like the ‘Limits’ section of the ‘Rigid Body Joint’ when ‘Pivot Type’ set to ‘Hinge’ in the properties window contstraints tab.)

You need to store the constraint in a variable:

constraint = constraints.createConstraint....

And use the attribute setParam with it variable:


constraint.setParam(0, 0.0, 0.0) #Limit the location in X axis
constraint.setParam(1, 0.0, 0.0) #Limit the location in Y axis
constraint.setParam(2, 0.0, 0.0) #Limit the location in Z axis

constraint.setParam(3, 0.0, 0.0) #Limit the rotation in X axis
constraint.setParam(4, 0.0, 0.0]) #Limit the rotation in Y axis
constraint.setParam(5, 0.0, 0.0) #Limit the rotation in Z axis

Somenthing like this:
setParam(axis, min, max)

        
        #Head
        edge_position_x = 0.0
        edge_position_y = 0.0
        edge_position_z = -0.5
        edge_angle_x = 0.055
        edge_angle_y = 0.0
        edge_angle_z = 0.0
        headConstraint = constraints.createConstraint(pid6,pid3,2,edge_position_x,
        edge_position_y, edge_position_z, edge_angle_x, edge_angle_y, edge_angle_z)
        headConstraint.setParam(0,-0.01,0.01)
        headConstraint.setParam(1,0.0,0.0)
        headConstraint.setParam(2,0.0,0.0)

This doesn’t give me an error, but nothing seems to have changed. I would expect the ‘head’ to barely move. Any idea what I’m doing wrong?

0.01 is a very low value, try increase it. Also, you want to limit the rotation or the movement? with that code you are limiting the movement in the local axis X a value of 0.01 and what type of constraint are you using? hinge?

Hi Carlo.

I did mean to Limit the rotation. I should have used 3,4,5 as the axis parameter. Oops!

I just want the rotation to be confined to the x axis for roughly 90 degrees.


        edge_position_x = 0.0
        edge_position_y = 0.0
        edge_position_z = 0.0
        edge_angle_x = 0.055
        edge_angle_y = 0.0
        edge_angle_z = 0.0
        headConstraint = constraints.createConstraint(pid6,pid3,2,edge_position_x,
        edge_position_y, edge_position_z, edge_angle_x, edge_angle_y, edge_angle_z)
        headConstraint.setParam(3,0.0,90.0)
        headConstraint.setParam(4,0.0,0.0)
        headConstraint.setParam(5,0.0,0.0)

This is still not working for me however :frowning: Any advice? Thanks for your help so far.

Ok, I was researching, and the setParam only work with 6dof constraint and the values need to be in radians.

Test this code:


constraint_type = 12 #12=6dof constraint
headConstraint = constraints.createConstraint(pid6,pid3,constraint_type,edge_position_x,
        edge_position_y, edge_position_z, edge_angle_x, edge_angle_y, edge_angle_z)

headConstraint.setParam(5,-1.57, 1.57) #1.57=90 degrees

PD: also in your penultimate script, that was changing the x axis, not the z, my error :smiley:

The constraint_type 12 is a rotating motor as far as I’m aware. The setParam(9,1.5,15.0) would set the axis to x the speed to 1.5 and acceleration to 15.0…

http://bgepython.tutorialsforblender3d.com/PhysicsConstraints/6DOF/RotatingMotor/createConstraint

My bad, think I’ve found what you meant.

Thanks for your help, I’ll edit my post as solved tommorow with an edit to my post.

Why not appear setParam in api?http://www.blender.org/documentation/blender_python_api_2_71_release/search.html?q=setparam&check_keywords=yes&area=default

Because it is not a design you can be proud of. The missing documentation just continues the quick&dirty approach.

The feature itself is nice, but the implementation misses a proper code review.

Example:


constraint.setParam(0, 0.0, 0.0) 

What is this code telling:
At a constraint a param (my dictionary says it is called parameter) is set.

What is the code not telling:

  • why are there multiple parameters?
  • what do the single values mean?

That is something the documentation should explain … but there is none.

A better approach would be this:


constraint.setLocationLimitOnAxis("X", -1.0, 1)

It still needs a documentation to explain the parameters and possible values. At least it is more specific on what it is supposed to do.

I guess an adapter class would be nice.

Then maybe it’s time someone would add this to the tracker as ‘todo’.

What happen in my blend? Other objects dissapear. Press p and then remove firts python script and press p again.When I create constraints all objects in scene except 1 disappear. I don’t understand nothing… Attach file

Attachments

constraints_what_happen.blend (612 KB)