Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Sphere acting like a ball in Bullet Physics

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Medo3337   Members   

891
Like
0Likes
Like

Posted 28 October 2012 - 06:02 PM

I have a sphere and trying to make it act like a ball, so when it move, it should rotate as well like physical ball, and when it hit something, it should bounce, here is the code I am using:
collisionShapes.push_back(colShape);
  /// Create Dynamic Objects
  btTransform startTransform;
  startTransform.setIdentity();
  btScalar mass(0.1f);
  //rigidbody is dynamic if and only if mass is non zero, otherwise static
  bool isDynamic = (mass != 0.f);
  btVector3 localInertia(0,0,0);
  if (isDynamic)
   colShape->calculateLocalInertia(mass,localInertia);
   startTransform.setOrigin(btVector3(0.0f,0.0f,0.0f));
 
   //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
   btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
   btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
   btRigidBody* body = new btRigidBody(rbInfo);
   dynamicsWorld->addRigidBody(body);
}

When I use the above code, the sphere does not rotate when moving (it's moving just like a normal box) neither it bounce when it hit the floor from gravity).

How can I get it to bounce and rotate while moving?

#2 Freya   Members   

831
Like
0Likes
Like

Posted 06 November 2012 - 03:21 AM

Is your colShape a btSphereShape? Another option is to give it more mass.

 
 


#3 MrRowl   Members   

2439
Like
1Likes
Like

Posted 06 November 2012 - 10:10 AM

It will only roll if it has friction.

Similarly it will only bounce if it has a non-zero restitution.

You can set these things in rbInfo. You'll also need to set them on the environment objects as well, because the resulting behaviour is determined by the combination of restitution & friction. Probably Bullet calculates them by multiplying the properties of the two interaction objects - so for starters, make restitution and friction = 1 on everything, and then modify it until you get the behaviour you want.

#4 Medo3337   Members   

891
Like
0Likes
Like

Posted 14 November 2012 - 02:32 AM

Thank you :)




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.