stephengold / Libbulletjme

A JNI interface to Bullet Physics and V-HACD
https://stephengold.github.io/Libbulletjme/lbj-en/English/overview.html
Other
84 stars 10 forks source link

how to push object? #29

Closed CrazyWords1 closed 4 months ago

CrazyWords1 commented 4 months ago

I created a sphere, when I run the test scene, the sphere drops and interacts with the colliders, everything is great in that, but when I try to apply (force) to the sphere, nothing happens. What i do wrong? P.S ( applyCentralImpulse(new Vector3f(-25f, 0f, 0f)) )

stephengold commented 4 months ago

@CrazyWords1 In general, applyCentralImpulse() ought to have some effect on the sphere's motion. I wonder about the sphere's mass and radius. Can you provide a simple test case?

CrazyWords1 commented 4 months ago

I can hardly provide a normal test case, I'm using a special environment for rapid development, not java. I think that may be the problem. But everything else works. Even the cars. I will try to provide the code in the necessary way, exactly the methods I use. I apologize in advance for my English, it's not my main language.

P.S(The test environment is compatible with java via reflection, i.e. all methods are called using java.lang.reflect)

func loadLibrary():
    downloadDirectory = new File("phys/")
    NativeLibraryLoader.loadLibbulletjme(true, downloadDirectory, "Release", "SpMt")

func createSphere(radius: number, loc: location, mass: number):
        //here was the code to create a visual model

        // _ prefix for local vars
    _sphere = new SphereCollisionShape(_radius/2)
     // :: aka array
    spheres::%_uuid% = new PhysicsRigidBody(_sphere, _mass) 

    physicsSpace.addCollisionObject(spheres::%_uuid%)

    spheres::%_uuid%.PhysicsLocation(locationToVector3(_loc))

        return spheres::%_uuid%
physicsSpace = new PhysicsSpace(PhysicsSpace.BroadphaseType.DBVT)

testSphere = createSphere(2, location(-348, 80, 381), 2)
testSphere.applyCentralImpulse(new Vector3f(-25, 0, 0))
timeStep = 0.01
while true:
   physicsSpace.update(timeStep, 0)
   updateVisual()
   //here func for sleep 50ms

P.S (Also wanted to add that if I use another method for testSphere, like applyCentruuulForce, I get the error, "No such Method, Perhaps you wanted to use applyCentralForce ? ")

CrazyWords1 commented 4 months ago

If you tell me that your code works differently, I'll go look for a bug in my environment, but it's strange that all other methods work. I also wanted to say a huge thank you for developing this library. For my game at the moment it's a major boon, the holy grail

stephengold commented 4 months ago

I verified that applyCentralForce() works as expected using tutorial code, specifically HelloRigidBody.

I don't see any major problems with your code, though it seems strange to update every 50 ms while advancing the physics by only 10 ms.

I wonder what would happen if you increased the magnitude of the impulse by 10x. Another debugging approach would be to print the velocity of the sphere after each physics update.

CrazyWords1 commented 4 months ago

While I was testing, decided to upgrade to the new version, everything broke :(

[17:34:01 INFO]: [com.jme3.system.NativeLibraryLoader] Loading native library from /home/crazywords/phys/Linux64DebugSp_libbulletjme.so
> Debug_Libbulletjme version 21.1.0 initializing
[17:34:01 WARN]: [com.jme3.bullet.util.NativeLibrary] Expected a v20.2.0 native library but loaded v21.1.0!
[17:34:01 INFO]: constructor PhysicsSpace#<init> called with (DBVT (BroadphaseType)) threw a NullPointerException: The construction info does not exist.

UPD (I went back to version 20.2.0, everything worked)

CrazyWords1 commented 4 months ago

Gosh, I don't know why, but after I went back to the old version and rebooted the server, everything worked, including applyCentralImpulse

stephengold commented 4 months ago

Between v20.2.0 and v21.0.0 there were incompatible changes to the API the JVM library uses to "talk to" the native library. If you upgrade one, you must upgrade the both. The warning indicates you somehow failed to do so.

CrazyWords1 commented 4 months ago

Thank you so much for the replies, at the moment with your advice, everything worked!

stephengold commented 4 months ago

I'm glad!