SphereCollisionShape cannot be scaled

When I started work on my current project I had spherical shields that would become smaller as depleted, recently updated jMonkey and I get the error: SphereCollisionShape cannot be scaled.

Is this a case of something not yet being implemented or is it unlikely to be? (I was surprised that you could scale physics objects at all, didn’t seem like a feature that would be commonly used)

Its not something we can decide, its so in bullet.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

Theoertically its possible
http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=5852
by using that other shape, but as it states, its probably just a waste of time doing so.

Meh, I won’t bother about it then. Just strange that it worked two/three months ago but doesn’t now.

@kd12 said: Meh, I won't bother about it then. Just strange that it worked two/three months ago but doesn't now.
You were able to call that method however it never did anything. The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there's emotes that hint otherwise or there's an increased use of exclamation marks and all-capital words.

Are you sure? I’m pretty sure it did :-/

I had spaceships that had shields that when depleted would shrink and after a period of not being hit would recharge and become bigger again, and it always seemed to work exactly as expected (for example, a projectile would have hit the shields at full strength but didn’t because they had reduced in size).

@kd12 said: Are you sure? I'm pretty sure it did :-/

I had spaceships that had shields that when depleted would shrink and after a period of not being hit would recharge and become bigger again, and it always seemed to work exactly as expected (for example, a projectile would have hit the shields at full strength but didn’t because they had reduced in size).


How would strength and size relate? I am not 100% sure but from what I tried the collision shape size did not change properly and the code in the sphere would also not really make it… Do you use jbullet or native bullet?
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

@normen said: How would strength and size relate?
I made them related because it looked cool, gave a quick and easy visual cue to the player, and because energy shields don't exist in real life.
@normen said: Do you use jbullet or native bullet?
I was/am using whatever the default is.
@kd12 said: I made them related because it looked cool, gave a quick and easy visual cue to the player, and because energy shields don't exist in real life.
:? You deduced from some "reduced strength" that the size of the collision shape was smaller. The collision shape is not visible or makes some "strength" be different, things just collide with it. The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there's emotes that hint otherwise or there's an increased use of exclamation marks and all-capital words.

The shields were like health, i.e. shields > 0% vehicle armour doesn’t take damage.

@normen said: You deduced from some "reduced strength" that the size of the collision shape was smaller.
I didn't "deduce" anything, I made it so.
@normen said: The collision shape is not visible
I also had a visible sphere spatial, the radius of which changed with the radius of the object in the physics space. Plus I had the visible debug physics thing on and that shrunk too if I remember correctly.

It’s hard to explain, but was clearly demonstrated by a few seconds of playing. Sadly I didn’t save an old version.

Shields shrinking as they are weakened potentially makes sense if you think about it,

… guys, I am not interested in this game but in the collision shape. Of course I get why he makes them smaller, I just don’t see how he should realize if the collision shape is actually smaller from visual cues or some “strength” because he cannot. So, he never knew the actual size of his collision shapes and also can’t say if they ever scaled.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

@kd12 told us he was displaying debug shapes. So it should give visual clues about it is working or not… Is this wrong?

Well in this case the old debug display was probably misleading, the old debug display would use the scaling value that was set. The debug display is also just a spatial like any other visual display for the shield would be :wink: Anyway from the post I can’t be sure if that is what the OP “saw”, thats why I was asking.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

@normen said: .... guys, I am not interested in this game but in the collision shape.
Hence I tried not getting into it in too much detail.
@normen said:So, he never knew the actual size of his collision shapes and also can't say if they ever scaled.
I am quite confident I did because if you shot projectiles at the shields they were impacting at different places and if you aimed near the edge of the sphere eventually they would miss because the sphere had shrunk too much and was no longer in the path of the projectiles. Also the shields would damage each other. In short, everything appeared to work exactly as it would if the spheres were scaling.

Long story short: something that may or may not have been possible and easy to do isn’t now and may or may not be possible in the future. Not a huge problem.

@zarch said: Shields shrinking as they are weakened potentially makes sense if you think about it,
That's what I thought too. 8)

Therefore, in you case, you have to remove the Ghost/RigidBody and add it again with the new size. Not as easy, but not that complicated either…

@yang71 Yeah, not sure I will bother, considering that in big battles that might be happening for dozens of ships everytime they update.

Well impacting projectiles is another thing. Maybe you can make a test case for this so I can investigate further.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

I might try reinstalling an older jMonkey (like the beta) and have a look when I have some time.

I just reinstalled jMonkey Beta, tried my game, the sphereCollision shape is DEFINITELY scaling, so I worked on a simple case that demonstrates it.

The following works in the beta version of jMonkey 3. I haven’t tried it in the most recent version.

Several spheres fall down, and a sphere in the centre of the screen grows. When the small spheres collide with the growing sphere they are removed.

[java]package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
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.Sphere;

public class Main extends SimpleApplication {

float timeSinceLastSpheres = 0.0f;
float timeBetweenSpheres = 1.0f;
float timeSinceProgramStarted = 0.0f;
Spatial growingSphere;

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

@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    
    stateManager.attach(new BulletAppState());
    stateManager.getState(BulletAppState.class).getPhysicsSpace().setGravity(new Vector3f(0.0f, 0.0f, 0.0f));
    stateManager.getState(BulletAppState.class).getPhysicsSpace().enableDebug(assetManager);
    stateManager.getState(BulletAppState.class).getPhysicsSpace().addCollisionListener(new SphereTestCollisionListener());

    this.growingSphere = createSphere(new Vector3f(0.0f,0.0f,0.0f));
    growingSphere.getControl(SphereRigidBodyControl.class).setMass(10000.0f);
}

@Override
public void simpleUpdate(float tpf) {
    //TODO: add update code
    timeSinceProgramStarted += tpf;
    if(this.timeSinceLastSpheres>this.timeBetweenSpheres){
        for(int i = -5; i<=5;i++){
            RigidBodyControl rbc = createSphere(new Vector3f(i,3,0)).getControl(RigidBodyControl.class);
            rbc.setLinearVelocity(new Vector3f(0.0f,-1.0f,0.0f));
        }
        this.timeSinceLastSpheres = 0;
    } else {
        this.timeSinceLastSpheres+=tpf;
    }
    
    float before = growingSphere.getControl(RigidBodyControl.class).getCollisionShape().getScale().length();
    growingSphere.getControl(RigidBodyControl.class).getCollisionShape().setScale(new Vector3f(this.timeSinceProgramStarted,this.timeSinceProgramStarted,this.timeSinceProgramStarted));
    float after = growingSphere.getControl(RigidBodyControl.class).getCollisionShape().getScale().length();
    //Comment the line below out to stop the spatial growing, and have only the collision shape grow
    growingSphere.scale(after/before);
}

public Spatial createSphere(Vector3f location){
    Sphere sphere = new Sphere(16,16, 0.1f);
    Geometry ball = new Geometry("Shiny rock", sphere);
    Material mat = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.White);
    ball.setMaterial(mat);
    rootNode.attachChild(ball);
    ball.setLocalTranslation(location);
    RigidBodyControl rbc = new SphereRigidBodyControl();
    ball.addControl(rbc);
    stateManager.getState(BulletAppState.class).getPhysicsSpace().add(rbc);
    return ball;
}

@Override
public void simpleRender(RenderManager rm) {
    //TODO: add render code
}

public class SphereTestCollisionListener implements PhysicsCollisionListener {

    public void collision(PhysicsCollisionEvent event) {
        SphereRigidBodyControl rbcA = (SphereRigidBodyControl)event.getObjectA();
        SphereRigidBodyControl rbcB = (SphereRigidBodyControl)event.getObjectB();
        if(rbcA!=null&&rbcB!=null){
            if(rbcA.getSpatial() == growingSphere){
                remove(rbcB);
            } else if(rbcB.getSpatial() == growingSphere){
                remove(rbcA);
            }
        }
    }
    
    private void remove(SphereRigidBodyControl srbc){
        if(srbc.getPhysicsSpace()!=null){
            srbc.getPhysicsSpace().removeAll(srbc.getSpatial());
            srbc.getSpatial().removeFromParent();
        }
    }
    
}

public class SphereRigidBodyControl extends RigidBodyControl {
    public Spatial getSpatial(){
        return spatial;
    }
}

}
[/java]

3 Likes