Asking for Expertise's Opinion for "the ultimate" solution

Please don't post Bullet support questions here, use the above forums instead.
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Asking for Expertise's Opinion for "the ultimate" solution

Post by KeKe »

Hi Guys,
This is my first post, so please don't fire at me if I asked something really stupid :oops:

First of all, This is a great Place to learn about physics knowledge and with such great physics engine actually make things a lot easier in the first place, thanks for all contributions :)

I'm new (very very new) to Physics simulation world indeed, this is my first physics engine touched, and tried to create a game out of it, but I've encounter a problem even though I don't know if it's normal.

I've searched the forum for almost a week, browsed all possible related threads. But for my question doesn't seem to be able to find a "perfect" solution.

Scenario:
I have a kinematic object that I can animate through changing it's position, and I have a dynamic object on top of the Kinematic object, but if I change the position (Gradually in small steps not like teleporting ) of the kinematic object, the dynamic object on top of the Kinematic object doesn't seem to move along with the "animate" kinematic object.. But I suppose there is friction on both object materials? so is this normal?

If it's not normal, could anyone point me a direction how can I make the dynamic object move along with the kinematic object?

If it's normal (the way this engine is designed), Could any expertise provide an "Ultimate" solution or a "better" solution for my case?

I've thought of some solutions but for me it feels like "Band-Aid" solutions..
1. Create constraints on the contact points when the 2 object is touched each other (is this possible? )
2. Just simply move the dynamic object position with the Kinematic when they got contact call back (is this possible? or is it good to do this way? )
3. Just simply set the velocity of the dynamic object with the kinematic object's velocity ( is this possible ? or is it good ? )
4. Just simply set the impulse on the dynamic object for each step simulation which might be the same with kinematic object ( is this possible? would it be out of sync for the 2 objects? )


Any Suggestions or Directions that's best suited for my situation would be much Appreciated :roll: :wink:

Thanks A Lot! :lol:
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by lulzfish »

If you're only setting the position, then Bullet is just sliding the kinematic object under the dynamic object, and assuming that you didn't want any physics to be invoked when you do that. No matter how big or small the steps, setting position is always considered to be teleportation from the engine's perspective.

I think most physics engines do this, it's something that makes sense to a human but is ambiguous to a computer (Because maybe you DO want to teleport something, and then it would be bad if the dynamic object flew away accidentally)

I would try setting the velocity of the kinematic object somehow, that way when Bullet checks on the collision, it will notice that one object is moving and the other is not, and it should apply friction. If it saw the object as "moving with velocity V" and not "teleporting in very small steps" then it should work.

There's a btRigidBody::setLinearVelocity (const btVector3 &), I would start there, assuming that kinematic objects also use btRigidBody.

Oh, and by "ultimate" you might be thinking of "best practice". http://en.wikipedia.org/wiki/Best_practices
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by KeKe »

lulzfish wrote:If you're only setting the position, then Bullet is just sliding the kinematic object under the dynamic object, and assuming that you didn't want any physics to be invoked when you do that. No matter how big or small the steps, setting position is always considered to be teleportation from the engine's perspective.

I think most physics engines do this, it's something that makes sense to a human but is ambiguous to a computer (Because maybe you DO want to teleport something, and then it would be bad if the dynamic object flew away accidentally)

I would try setting the velocity of the kinematic object somehow, that way when Bullet checks on the collision, it will notice that one object is moving and the other is not, and it should apply friction. If it saw the object as "moving with velocity V" and not "teleporting in very small steps" then it should work.

There's a btRigidBody::setLinearVelocity (const btVector3 &), I would start there, assuming that kinematic objects also use btRigidBody.

Oh, and by "ultimate" you might be thinking of "best practice". http://en.wikipedia.org/wiki/Best_practices

Thanks a lot lulzfish!!
That really clarifies a lot of things to me, and thanks for correcting my poor English.. :oops:
However, In my situation, I have a Kinematic object that user can control, which is to be able to be dragged by the user's mouse, so if I set the linear velocity, which the object might not be sync-ing with the mouse movement, is there anyway I can do this with velocity setting and still sync with the movement of the mouse?? :shock:

In the meanwhile, I'll keep trying down this path, Thanks a lot for the help! :)
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by lulzfish »

KeKe wrote:In my situation, I have a Kinematic object that user can control, which is to be able to be dragged by the user's mouse, so if I set the linear velocity, which the object might not be sync-ing with the mouse movement, is there anyway I can do this with velocity setting and still sync with the movement of the mouse?? :shock:
I think it can work if each frame does something like this:

1. Get the new mouse position
2. Generate the new kinematic location from the mouse position
3. let movementVector = newPosition - currentPosition
4. Either:
4a. let velocityVector = movementVector * steppingRate
4b. let velocityVector = movementVector / steppingRate
(I think it is probably divide, but I haven't tested these)
5. Overwrite the kinematic's velocity with velocityVector
6. Step Bullet

And of course, if the mouse isn't being used, reset the velocity to 0 so the object doesn't fly away when the user lets go of it.

That way at each frame, the kinematic object will be given exactly enough velocity for Bullet to move it to the new mouse position within the next physics step.
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by KeKe »

lulzfish wrote:
KeKe wrote:In my situation, I have a Kinematic object that user can control, which is to be able to be dragged by the user's mouse, so if I set the linear velocity, which the object might not be sync-ing with the mouse movement, is there anyway I can do this with velocity setting and still sync with the movement of the mouse?? :shock:
I think it can work if each frame does something like this:

1. Get the new mouse position
2. Generate the new kinematic location from the mouse position
3. let movementVector = newPosition - currentPosition
4. Either:
4a. let velocityVector = movementVector * steppingRate
4b. let velocityVector = movementVector / steppingRate
(I think it is probably divide, but I haven't tested these)
5. Overwrite the kinematic's velocity with velocityVector
6. Step Bullet

And of course, if the mouse isn't being used, reset the velocity to 0 so the object doesn't fly away when the user lets go of it.

That way at each frame, the kinematic object will be given exactly enough velocity for Bullet to move it to the new mouse position within the next physics step.
Hi lulzfish,
I'm currently trying the method you suggested, but I got something wants to clarify a bit since I'm so new to Bullet :oops:

I tried to set the "setLinearVelocity" of my Kinematic object, but it doesn't seem to be moving?? while trying on the normal "dynamic" object(mass=10) is working fine, I just want to know if this is normal that I can't set kinematic objects' velocity? or if it's not, am I having something setup wrong?

As in my knowledge, I know that by setting mass = 0, and "flag" to Kinematic I can control it, but when I use setLinearVelocity, it doesn't seem to work, :? just confused.. :shock:
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by lulzfish »

I haven't actually used Bullet much, but I think this thread is similar to your problem:
http://www.bulletphysics.org/Bullet/php ... &f=9&t=688

Erwin recommended (4-5 years ago, hope it's still right) to disable sleeping on kinematics that need to be moving around.

And apparently you can subclass btMotionState somehow to create a controller for a kinematic object, then Bullet will automatically calculate its velocity every frame if you send the position and rotation through the motion state.
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by KeKe »

lulzfish wrote:I haven't actually used Bullet much, but I think this thread is similar to your problem:
http://www.bulletphysics.org/Bullet/php ... &f=9&t=688

Erwin recommended (4-5 years ago, hope it's still right) to disable sleeping on kinematics that need to be moving around.

And apparently you can subclass btMotionState somehow to create a controller for a kinematic object, then Bullet will automatically calculate its velocity every frame if you send the position and rotation through the motion state.
Thanks a lot lulzfish!
I've saw that thread already and I did everything that Erwin suggested to do, I set the Kinematic flag and also deactivate the sleep but I still can't move the object by "setLinearVelocity", :cry: I also tried "HARD" to understand the CcdPhysicsDemo too, but still doesn't get any luck :cry: (probably because my lack of experience in physics simulation concept? :oops: )

Because I'm relatively new to this field not only with Bullet but the whole physics simulation stuff, so the MotionState method seemed to be a lot more complicated than I could conquer. I still think that such an easy problem shouldn't need any "customized" motionstate.. :cry:

Anyway, I'll try all my best to keep working on this issue, but still thanks a lot for all the suggestions and advises lulzfish, God Bless You!! :lol:

If I got any further progress I'll come up and post a solution :D
If you come up with any other ideas please don't hesitate to share it, Thanks! :D
ngbinh
Posts: 117
Joined: Fri Aug 12, 2005 3:47 pm
Location: Newyork, USA

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by ngbinh »

I thought setting the body to be Kinematic and control it by setting velocity should work as you expect. If not, it should be simple to fix too.
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by KeKe »

ngbinh wrote:I thought setting the body to be Kinematic and control it by setting velocity should work as you expect. If not, it should be simple to fix too.
Hi, Thanks for the comment, but I really don't know how to check because the 3D engine I'm using is SIO2, and I'm not sure if it's because some setting I'm missing for SIO2 or not, I just can't get the Kinematic object to move with "setLinearVelocity" even though I checked all the settings suggested here by Erwin (Set object mass=0, set deactivate flag, set object to Kinematic flag), I have no clue at all and don't know where to start debugging...

But I surely "CAN" move the rigid body with "setLinearVelocity" without any problems at all. I don't even need to set the object to be Kinematics. But I can't use rigid body since it must be given a Mass, which caused my desired object to have "gravity effect" that I don't want on my Kinematics object.

Well I'll still keep trying with my limited knowledge about Bullet, but if anyone else have better suggestion or might know there are some settings might affect a little please don't hesitate to share! :)

Thanks a lot! :)
KeKe
Posts: 6
Joined: Mon Jan 03, 2011 3:00 pm

Re: Asking for Expertise's Opinion for "the ultimate" soluti

Post by KeKe »

KeKe wrote:
ngbinh wrote:I thought setting the body to be Kinematic and control it by setting velocity should work as you expect. If not, it should be simple to fix too.
Hi, Thanks for the comment, but I really don't know how to check because the 3D engine I'm using is SIO2, and I'm not sure if it's because some setting I'm missing for SIO2 or not, I just can't get the Kinematic object to move with "setLinearVelocity" even though I checked all the settings suggested here by Erwin (Set object mass=0, set deactivate flag, set object to Kinematic flag), I have no clue at all and don't know where to start debugging...

But I surely "CAN" move the rigid body with "setLinearVelocity" without any problems at all. I don't even need to set the object to be Kinematics. But I can't use rigid body since it must be given a Mass, which caused my desired object to have "gravity effect" that I don't want on my Kinematics object.

Well I'll still keep trying with my limited knowledge about Bullet, but if anyone else have better suggestion or might know there are some settings might affect a little please don't hesitate to share! :)

Thanks a lot! :)

Hello, I actually used a "band-aid" solution because I really can't get my kinematic object to move with setLinearVelocity

The way I do it is funny, I use transformation instead of setLinearVelocity to move the object, but still call setLinearVelocity to apply the velocity on the Kinematic object. The Bullet solver can calculate the interaction between any dynamic object with the Kinematic object and apply the proper friction simulation, and it actually works quite well...

I just don't think it is the proper way to do it, but since currently can't get Kinematic object to move with setLinearVelocity, I just use normal transformation I used before to change the location but yet setting the velocity at the same time....

This is pretty funny to me :lol: but currently can't get any better than this.. :oops: