I am substituting my collision and tiny physics library with Bullet for my game. And I am new to Bullet so this might be a stupid question. And sorry my English.
In my game, with my physics library, monsters move around in terrain by AI control with FK animation. If a monster will collide with wall or other obstacles in near future, make the velocity to 0 and change the AI state to other. If collision occurs, apply impulse(restitution) to do not penetrate each object.
This scenario is nothing special. I am trying to realize this scenario by Bullet. I want to determin monster's next position and orientation with like below sudo code;
Code: Select all
// AI wants to make monsters to move x0 to x1(Kinematics).
class Monster monster; //assume this class inherits or has btRigidBody instance with cylinder shape bv.
Vector3 x1 = vdt + x0;
Transform transform;
transform.setOrigin( x1 );
transform.setOrientation( orientation );
monster.setDesiredWorldTransform( transform );
// by step simulation, monster's final position will be determined(Physics).
DynamicsWorld.stepSimulation(...);
Transform finalTransfrom = monster.getFinalWorldTransfrom();
I am currently doing trial and error to realize this, like, this looks similar to CCD functionality so I have tried to set desired position by setInterpolateWorldTransform() method but did not work as predicted. also tried proceedToTransform() method did not work. Using ghost object may be different scenario.
Now I want to know how to realize such mixing kinematics and physics with Bullet.
I should read and understand source code though, but if there is a good solution that suits this purpose I appreciate.
Addendum:
-One thing that could be a solution that I am considering is, calculate impulse by p = dx/dt*mass and apply the impuse to monster, but problem is friction, inertia, inertia tensor and other factor which I am currently not knowing must be counted to make it precise. it seems not easy for me to build such function p = f( dx, dt ).
-I could barely realize above method about translation but friction nor orientation. I need to clear values of linear, angular velocities and total velocities, and called setCentralImpulse() method to set calculated impulse every frame. so it was necessary to divide the impulse by dt. I am still looking for a better solution.