[SOLVED] Cant Scale rigibody even using the collisionshape.setscale

Hi, I found information about how to scale an active object but I tried and its not working.
In the wiki it says you can setScale using …(RigidBodyControl.class).getCollisionShape().setScale , if the spatial has rigidbodycontrol it suppose to scale.

My constructor :

... 
Torus torusBombMesh = new Torus(32, 32, 0.2f, 1f);
spatial = new Geometry("Torus", torusBombMesh);
...

    BoundingSphere boundingSphere = new BoundingSphere();
    spatial.setModelBound(boundingSphere);
    spatial.updateModelBound();
    SphereCollisionShape sphereCollisionShape = new SphereCollisionShape( boundingSphere.getRadius() );
    RigidBodyControl torusKinematic = new RigidBodyControl( sphereCollisionShape , 0.1f );
    spatial.addControl(torusKinematic);
    torusKinematic.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(torusKinematic);

In the controlUpdate :

    spatial.scale(1 + (currentBombExplosion/2)*tpf);
    spatial.getControl(RigidBodyControl.class).getCollisionShape().setScale(new Vector3f(1 + (currentBombExplosion/2)*tpf, 1 + (currentBombExplosion/2)*tpf, 1 + (currentBombExplosion/2)*tpf));

What am I missing ?
Do I need to recreate the collisionshape every frame ?

No one ?
I have tried everything , recreate CollisionShapeFactory.createMeshShape on physics tick , use default rigidbody instead of the sphere I want to use, recreate the collisionshape, nothing seens to work :frowning:

What DebugBulletAppState shows? Even recreating the collisionShape (when it’s not on physics space, as Javadoc says) it won’t change on scene?

Nop, it wont change it, ether in the physics or in the debug.
It maybe because of the torus, I dont know.

On above example code, you just scale the CollisionShape, but you don’t reattach it. Provide us the updated code with removing the control from physics space, scaling the collisionShape, updating the collision shape on rigidBody and attaching control from physics space.

Also, I think the spatial.scale is wrong, what you want is spatial.setScale, no? because scale is incremental already, while currentBombExplosion is incremental also.

Test case :

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingSphere;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Torus;

public class Main extends SimpleApplication {

    Spatial spatial;
    BulletAppState bulletAppState;
    RigidBodyControl sphereKinematic;

    public static void main(String[] args) { new Main().start(); }

    @Override
    public void simpleInitApp() {
        // setup bullet physic engine
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        bulletAppState.getPhysicsSpace().setGravity(Vector3f.ZERO);
        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        bulletAppState.getPhysicsSpace().setAccuracy(1f / 60f);

        // setup torus
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        Torus torusBombMesh = new Torus(32, 32, 0.2f, 1f);
        spatial = new Geometry("Torus", torusBombMesh);
        spatial.setMaterial(mat);
        rootNode.attachChild(spatial);

        // setup physic body
        BoundingSphere boundingSphere = new BoundingSphere();
        spatial.setModelBound(boundingSphere);
        spatial.updateModelBound();
        SphereCollisionShape sphereCollisionShape = new SphereCollisionShape( boundingSphere.getRadius() );
        sphereKinematic = new RigidBodyControl( sphereCollisionShape , 0.1f );
        spatial.addControl(sphereKinematic);
        sphereKinematic.setKinematic(true);
        bulletAppState.getPhysicsSpace().add(sphereKinematic);
    }

    @Override public void simpleUpdate(float tpf) {
         spatial.scale(1 + 0.1f*tpf);

         // not working : setradius , setScale , updatemodelbound etc.
         BoundingSphere boundingSphere = new BoundingSphere();
         //boundingSphere.setRadius(boundingSphere.getRadius() *( 1 + (currentBombExplosion/2)*tpf ) );
         spatial.setModelBound(boundingSphere);
         spatial.updateModelBound();
         SphereCollisionShape sphereCollisionShape = new SphereCollisionShape( boundingSphere.getRadius() );

         //sphereCollisionShape.setScale(new Vector3f(1 + (currentBombExplosion/2)*tpf, 1 + (currentBombExplosion/2)*tpf, 1 + (currentBombExplosion/2)*tpf));
         //CollisionShape CollisionShape = CollisionShapeFactory.createMeshShape( spatial );
         sphereKinematic.setCollisionShape(sphereCollisionShape);
    }

    @Override public void simpleRender(RenderManager rm) { }
}

As I said, you are no doing what Javadoc says:

@Override 
public void simpleUpdate(float tpf) {
     spatial.scale(1 + 0.1f*tpf);
     spatial.updateModelBound();

     //Remove RigidBodyControl from Physics Space.
     sphereKinematic.setEnabled(false);

     //Get current sphereCollisionShape and scale it.
     SphereCollisionShape sphereCollisionShape = (SphereCollisionShape) sphereKinematic.getCollisionShape();
     sphereCollisionShape.setScale(spatial.getLocalScale());

     //Reattach it to RigidBodyControl
     sphereKinematic.setCollisionShape(sphereCollisionShape);

     //Add RigidBodyControl to Physics Space again
     sphereKinematic.setEnabled(true);
}

Humm, I guess not…
I was following the wiki, I guess its incomplete.
Thanks friend, its working now.

When something does work by following Wiki, check Javadoc, because Wiki can be outdated, but Javadoc is harder.