SetLocalScale and Physics (17 posts)

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    Right I need this to be cleared up.

    I have a model, I load it in, and i dont make any calls to setLocalScale. It works and my other objects bounce of it etc as it should expect from the physics support.

    I then load my model – call setLocalScale(100); to make it 100 times larger, and then create the CollisionShape etc and my other models just float through the model, as if its been scaled up , but the physics side doesnt think it has?

    How is this meant to work – and why isnt it working!

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    As stated multiple times in the forum and now in the javadocs as well: CollisionShapes dont scale withe the PhysocsNode as they can be used for multiple PhysicsNodes. Scale the CollisionShape as well or creeate it after scaling the original node/mesh.

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    I am scaling it before…. yet after scaling my models fall straight through the object

          Spatial scene = assetManager
                .loadModel("resources/misc/Plane.mesh.xml");
          scene.setLocalScale(new Vector3f(100,100,100));
          CollisionShape hillCollisionShape = CollisionShapeFactory
                .createMeshShape(scene);
    hillCollisionShape.setScale(new Vector3f(100,100,100));
          hillNode = new PhysicsNode(scene, hillCollisionShape, 0);
       
    

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    renegadeandy said:
    I am scaling it before…. yet after scaling my models fall straight through the object

    If your Spatial is a Node the changes to the children wont be propagated until you call updateGeometricState(); on the Node. I added this call to the latest svn in createMeshShape but you could also try adding spatial.updateGeometricState(); after setting the scale and see if it works then.

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    OK I did – but it still just falls straight through.

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    renegadeandy said:
    OK I did – but it still just falls straight through.

    What else did you try? Scaling the CollisionShape itself maybe? Does that work? Maybe you can try making the collision shape by hand (either combining mesh shapes to a compound shape or just using one single mesh shape). I have done this multiple times and the Q3Test also works like this, somethings got to be wrong..

    Also, in the code you posted, you first scale the Model, then create the CollisionShape and scale the CollisionShape again afterwards. That is not going to work, this way the CollisionShape is already created "big" and then you scale it in addition to that. Scale the Model first and make the collision shape, then the scale is included in the CollisionShape.

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    Ok so I tried what you said and it makes no difference.

    IS it possible to draw an overlay or something to show what the collisionShape which is created actually looks like – that would massivly help debugging…

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    No, there is currently no debug view. I cant imagine that making a single MeshCollisionShape (not a compound shape) of a geometry in the loaded spatial did not work properly. Did you really try without the ShapeFactory? Post the model and I will see what I can do.

    Edit:
    This code in the Q3 test works just fine:

          
    gameLevel = (Spatial) assetManager.loadAsset(key);
    gameLevel.setLocalScale(0.1f);
    CompoundCollisionShape levelShape = CollisionShapeFactory.createMeshCompoundShape((Node) gameLevel);
    PhysicsNode levelNode = new PhysicsNode(gameLevel, levelShape, 0);
    

    And the final thing: I hope your models are not using Mesh shapes as well? Then they will not collide with other mesh shapes anyway.

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    Aha – i fixed it.

    Changed from BoxCompoundShape to a dynamic mesh shape on the player – and it now works!

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    Although regardless the model will still somehow find a hole and fall through the terrain when i try applying some forces to it.

    Attached is the model for you to test.

    http://www.mediafire.com/?b7la2nkjeb5mv82

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    Well, if the box fell through it was not configured right. Seems like the problem is more with your player model than the terrain. I strongly suggest not to use gimpact meshes but basic shapes for movables. Gimpacts ("dynamic" mesh shapes) are very expensive.

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    So my player model atm is a snowboard, so if i just gave that a simple box collision shape – perhaps that would be better?

    <I have now tried this – the only one which works i.e stops the snowbaord from falling through the terrain is the createDynamicMeshShape>

    Perhaps the snowboard object is wrong??

    Can you try it with the terrain i posted earlier.

    –>Snowboard –>http://www.mediafire.com/?p73y7cdpv7p2d74

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    What I can see by loading the board model in jMP is that its not centered, maybe thats one reason for weirdness when creating a collision shape for it. In a PhysicsNode with a correctly sized box as CollisionShape for example the board attached as child would be visible "under" (-Y) the collision shape center and seemingly fall through the floor (but stop when the collision shape "above" it hits the ground).

  • Profile picture of renegadeandy renegadeandy said 1 year, 6 months ago:

    Ahh ok that sounds possible.

    What is jmp? Sounds a useful tool for model debugging.

    However that shouldnt really cause the model to fall through the terrain on a box collision shape – surely it would just offset the visuals and the actual shape.

    Having some form of collision shape debugging would be incredibly useful again – as i could draw a red line around what the collision shape is – and see if its accurate to the model!

  • Profile picture of normen normen1022p said 1 year, 6 months ago:

    renegadeandy said:
    Having some form of collision shape debugging would be incredibly useful again – as i could draw a red line around what the collision shape is – and see if its accurate to the model!

    orly?

    renegadeandy said:
    What is jmp? Sounds a useful tool for model debugging.

    jMonkeyPlatform, the Game Development Environment for jme3: http://www.jmonkeyengine.com/wiki/doku.php/jme3:jmonkeyplatform