AttributeError: KX_GameObject.localLinearVelocity is missing a physics controller

I get this error and I can’t seem to find a way to bypass it. The localLinearVelocity command is used to move a camera. It worked before I parented the camera(as a child) to an empty, and the empty(as a child) to the vertices of a cube, so I think this is somehow connected. Any thoughts?

Thanks

You cannot assign velocity to an object without a physics controller.
This will occur if an object has no mesh, and you do not assign any collision bounds (e.g Empty, Camera)

it doesn’t only say that for static object also for dynamic etc., i had the same with my save/load system.

You just need to check for the id.

 if obj.getPhysicsId():                
    obj_data['velocity_L'] = list(obj.worldLinearVelocity)
    obj_data['velocity_A'] = list(obj.worldAngularVelocity)

@@agoose77 : It worked fine before the parenting though.And I have set the camera “dynamic” in the physics, altough I did not activate any bounding boxes.On the other hand I never did activate them when it worked also.

@@Cotaks : I played a bit with this,but did not get it to work. Isn’t the linear/angular velocity a list already? So I create a dictionary from a list, would this be like a [Edit]2x2 matrix with 1 element[/Edit]? Also if I could draw the linear/angular velocity values already I guess then I could change them too. So how does this code help me? The cam.getPhysicsld() gets me a value of 0. Should this be affecting me? Can you explain me how to work with what you wrote? Thanks!

The above is just an example code for the check.

if obj.getPhysicsId():

in your case u can just do something like:

if obj.getPhysicsId():
camera.worldLinearVelocity = ‘something’

this check will get rid of the errors, but if it returns a zero it indeed has no physicsId.

You say you got it parent to an empty this again to a cube, so the cube is the main object with an physicsId.
What if you loop trough the childs of the objects, and then apply it to the child?

This is the .blend file. I have the module inserted as a block.The lines that you might be interested are 26 to 45. I left the getPhysics command as a comment above. Can you check it out?

Attachments

scripting a LoL camera_test.blend (497 KB)

If you parent a physics object to another object it becomes a static object.

Therefore there is no velocity anymore.

@@Monster thanks for the info! Do you see any way of overcoming it without changing the general idea or do I need to find a different path. Can I change any settings or must I clear the parent? Now that I am writing this I am thinking of playing with the worldPosition of the camera,although it would not be as smooth as intented. I am open to suggestions.

If you think about it makes sense, The object is parented to another object. Therefore the parent determines what the following motions of the object. It makes not much sense to calculate any physical behavior as it will be overridden by the parent.

You might want a different sort of relationship such as rigid body constraint or compound object. Compound object uses parenting to, but needs to be configured beforehand. Rigid body constraints can be created via GUI and via Python. I do not have much experience with both methods as I usually do not use them.