How to change scale of a physics object

I am trying to change the physics object scale in the update loop. I create a Spatial and attached a RigidBodyControl to the spatial. I updated the Spatial scale but the physics doesn’t get updated

Thank in andvance.



[java] for (int i = 0; i < rootNode.getChildren().size(); i++) {

Spatial b = rootNode.getChild(i);



if(b.getName().equals(“Block”)){

b.setLocalScale(b.getLocalScale().x*1.01f);

}

}[/java]

1 Like

You have to scale the collision shape…

1 Like

I am using this:



b.getControl(RigidBodyControl.class).getCollisionShape().setScale();



However nothing is happening.



updated code:



[java]for (int i = 0; i < rootNode.getChildren().size(); i++) {

Spatial b = rootNode.getChild(i);



if(b.getName().equals("Block")){

b.setLocalScale(b.getLocalScale().x*1.01f);

b.getControl(RigidBodyControl.class).getCollisionShape().setScale(b.getLocalScale());

}

}[/java]

b.getControl(RigidBodyControl.class).setCollisionShape(b.getControl(RigidBodyControl.class).getCollisionShape().setScale(b.getLocalScale())) maybe?

Addez no it doesn’t work. I split up the command too.



[java] CollisionShape tmp = b.getControl(RigidBodyControl.class).getCollisionShape();

b.setScale(new Vector3f(5,5,5));

b.getControl(RigidBodyControl.class).setCollisionShape(tmp);[/java]



updated code:



[java]for (int i = 0; i < rootNode.getChildren().size(); i++) {

Spatial b = rootNode.getChild(i);



if(b.getName().equals(“Block”)){

b.setLocalScale(new Vector3f(10,10,10));

CollisionShape tmp = b.getControl(RigidBodyControl.class).getCollisionShape();

b.setScale(new Vector3f(10,10,10));

b.getControl(RigidBodyControl.class).setCollisionShape(tmp);

}

}[/java]

Try making a new collision shape, it will not yield a proper “physical” effect like blowing up a ballon or something anyway.

1 Like

@funbox in that code above you are just getting the collisionshape and just setting it to itself. You don’t change it

1 Like

Wezule it was a typo



updated code:

[java]for (int i = 0; i < rootNode.getChildren().size(); i++) {

Spatial b = rootNode.getChild(i);



if(b.getName().equals("Block")){

b.setLocalScale(new Vector3f(10,10,10));

CollisionShape tmp = b.getControl(RigidBodyControl.class).getCollisionShape();

tmp.setScale(new Vector3f(10,10,10));

b.getControl(RigidBodyControl.class).setCollisionShape(tmp);

}

}[/java]

1 Like