Changing the size of Physics object

Jan 28, 2011 at 12:23 PM

Hi, I am new to Physicshelper, but managed to create a Line object and make it as a Physics object and add Physics behavior to it through code.

After making the physics object and add behavior to it, I am changing the size (reducing to about half the length)of the line on a button click.

My problem is after the change in size the line still behaves like the actual long line instead of shortened line?

Why is this happening? How can i apply behavior to the re-sized object? Thank you.

Jan 28, 2011 at 1:44 PM

I believe this happens because the boundary detection algorithm is only scheduled to do it's work as soon as an object is added to the Physics Controller. You can change the VisualElement (or 'uielement') to whatever you'd like, but the physical boundaries of the object (as far as the simulator is concerned) remains the same. I tried re-setting the BoundaryElement to something else (during gameplay) but this didn't work as well. Looking through the source code, it appears that even the (alternative) BoundaryElement only replaces the actual object's boundary when it is first added to game.

Off the top of my head, a workaround could be as follows: on the click of the button, remove the PhysicsObject of the (longer) line completely. Then add another (shorter) line from scratch once again (probably at a relative position give the impression that the line shrank). Quite instinctively, we may assume that this would consume much more computation than required, lagging the gameplay. But, in my opinion, most of the work is done in the actual boundary detection itself, and since this needs to be redone anyway, it shouldn't make that much of a difference.

Jan 31, 2011 at 9:09 PM

Hi Arkuana,

Regarding the workaround you have mentioned, i tried it in two ways:

1) Remove the physics behavior of the line:


PhysicsObjectBehavior staticObject = new PhysicsObjectBehavior();


//Adding object to behavior






//Adding behavior to object

BehaviorCollection bc2 = Interaction.GetBehaviors(this.testLine);




2) Delete the physics object (name of the line is testLine) from the physics controller:





In all the above mentioned scenarios i was not able to make the line as a non physics object.

Could you please post some code on how this can be done?

Thank you.