Mixing kinematics and physics

nakashima@ss
Posts: 4
Joined: Wed Apr 17, 2013 1:44 am
Location: Tokyo, Japan

Mixing kinematics and physics

Post by nakashima@ss »

Hello,
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(); 
x1 is determined by AI and this is the desired position the monster supose to be if there is no collision in next frame. As monster moves position x0 to x1, there might be some collision with other objects and there might be restitution and so on, I want to let Bullet do this part because this is the exact reason I use Bullet.

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.
Jyavoc
Posts: 13
Joined: Fri Apr 05, 2013 6:19 am
Location: Pittsburgh, PA

Re: Mixing kinematics and physics

Post by Jyavoc »

One of the things you might find a bit easier to work with is, instead of setting the new position, you could set the linear velocity of monster, using a velocity that would be enough to move monster from x0 to x1 in the desired time. If the difference between x0 and x1 is (10, 0, 0), and you want to travel this in 1 second, you could set the linear velocity to btVector3(10.0, 0.0, 0.0). Or if you wanted to travel that in half a second, the linear velocity might be btVector3(20.0, 0.0, 0.0). I could be wrong, but I think that working with velocities and letting Bullet manually calculate the new position is much easier than doing it manually.

Also, when collision is detected between two objects, Bullet will automatically make them respond in the appropriate ways (bounce away, stick, bounce off, etc). You shouldn't need to check for yourself if they have collided, and you won't need to apply an impulse. Bullet will do this for you.
nakashima@ss
Posts: 4
Joined: Wed Apr 17, 2013 1:44 am
Location: Tokyo, Japan

Re: Mixing kinematics and physics

Post by nakashima@ss »

Jyavoc,
Thank you for your reply.
I agree with you because your idea is almost same as what I mentioned in addendum of my article. I expressed linear velocity as impulse which is mult linear velocity by mass. The problem is friction or other factor must be counted to be precise.