Python Parent Problems??

So I am trying to piece together a simple script which parents everything in the scene to an object, which is just an empty at the moment. I am setting the parent with .setParent(parent) and that seems to work, but the rigidbody in the scene doesnt react to gravity or anything once parented.

Is there anyway to get every object in the scene parented to one object and keep all the physics and everything the same for the children? And also be able to move the parent as well?

I’ve attached a bare bones blend file to try and show my troubles. Just enable and disable the script in the logic view to see the difference. It seems to be a very basic problem, just cant seem to get around it.

Thanks guys

Attachments

Offsetter.blend (519 KB)

yes , must using a rigidBodyJoint.(without parent)

but need to be mesh obj(not empty)

else, you can simulate the physic with python

Why do you want all objects be children of one object?

If you parent a physics object you disable the physics as the location/rotation gets fixed to the parent. This is what parent means. Physics objects simply do not have a parent.

wow, you’re an expert on parent!? :smiley: :wink:

but if you setParent (During the game, not in edit mode) not work all well? (the ray work?)

how say Monster WHEN the object is children is right (is logic) which lost his physic property (is thath which we want in 99% of cases)

marcoIT: for most things the parent tools work well (Python/ logic) but for the game I am making I would need some very specific things that are just not possible with the parent options.

For example, with setParent, I was making a script that takes the mass value from the child and adds it to the parent. With Flexicomp this is not needed as there is no parent / child relationship like there is with setParent and real time attributes (like mass) are kept active.

In context, my game is (as you know from other posts) a racing game that has ships that carry their weapons and drop them when they are used up. Now, with the setParent, I had to choose:

have ships with separate chunks (that could be hit individually) but each child chunk would be a ghost (which looks silly when it flies through other objects)

have a compound object that could not have pieces that could be hit (as compound objects register hits for the parent only) but each piece would have a collision hull

Either option was a compromise. Luckily I could use the simulated 6dof joints and this was perfect for me.

ah , yes , probably ther parent is a bit too “approximate” (superficial)

anyway , i neverer see more than some cube (without even texture!)! :eyebrowlift2: :evilgrin:

anyway , i neverer see more than some cube (without even texture!)!

:yes:Hopefully that will change! When I first started using Blender to make games I forced myself to do the programming/ logic first so I never got into the position of having good looking models but no game to put them in.

But then I realised there is so much to do in a game…every problem needs a solution and although its a challenge its fun to see things work!

And I imagine you will see more of those cubes before long when I come across another bug:evilgrin::wink:

see my post below

yes , i know the “test phase” (is long…)

is necessary but some “crap game” can be done anyway meanwhile :wink:

you can learn also in this way

And I imagine you will see more of those cubes before long when I come across another bug:evilgrin

super LOL :smiley: :evilgrin: :wink:

Hi guys,

Thanks for the great replies, rubber nuke that was a brilliant post all about parenting. Really cleared things up for me. I am getting precision errors when my player goes far from the centre point, making the meshes wobble and act quite weird. I am trying to parent everything in the environment (including the player) to one item so that I can “reset” the players position without them noticing. Just to help with the precision errors(at least that’s what I think is causing the wobbles).

I was getting confused when I was trying to implement it within the game level, so I made a very basic example of where I am stuck, which is why it’s only a cube in the blend I attached.

I think I can do this by parenting everything to one item in the outliner (not in the bge) but was just seeing if it could be done without having to do that. I did not know that you loose the physics when you use setParent(), but I suppose that makes sense and would be used most. oh, just tried it there, you can’t have the rigid body parented to something them move it with forces etc…

@Monster yea that was a bit shortsighted of me. I didn’t think the parent would work like that. I thought you could have an empty, parent a rigid body to it, then have the rigid boy move independently of its parent.

I was getting really confused with the ghost / compound settings, but I think I understand now. Going to have another stab at this tonight with all this new information. Does anyone know of a different way of keeping the player quite near [0,0,0] including the environment? I thought this would be quite a simple task, as it was easy to implement in the Unity engine. With that you can have dynamic objects that do NOT take on its parents physics propeties.

I will have a look into Flexicomp Marco but I have a feeling it’s not what I’m looking for. Useful tool to have though. I should have stated what I was trying to accomplish in my first post, sorry about that, but there is a load of really useful info about parenting here now, so silver lining.

Cheers guys

Sorry to double post, but does anyone know how I can do this? I’m not sure if I should find another work around or keep going with this? If you cant be bothered reading through my bloated post above, then:

I am getting precision errors when my player strays far from the centre point and the mesh starts to wobble and act a bit strange. I am trying to find some way to keep the player quite near to the centre point of the ge, whilst still travelling through the environment. I could either parent the entire environment and player, then offset the position of the parent to keep the player at point [0,0,0]. This could be done when the player reaches, say, 2000 units from the centre point, or every 3 seconds or something.

I just dont know a good way to do this. Any tips? I have already learned so much about parenting from this thread, but still cant solve my problem.

Thanks guys

What do you want this for, may I ask? (Or what are trying to do, game wise?