creating a ball

Fred

24-08-2008 23:49:34

Hi there,
Has anybody already created a realistic jumping and rotating ball?
Can you tell me what "movement options" I have to set?

At the moment my code for move a ball looks just like:
m_pBody->addTorque(m_Thrust * 30000);
m_Thrust ist a vector3 which is set on (1,0,0) when a key was pressed and which ist set on (0,0,0) when a key was released.
The result does not really looks like a realistic ball. The "object" turns around its own axis, but the rotation stops immediately after releasing the key.
Have you any tips for me, how to create a ball?

Thanks
Fred

betajaen

25-08-2008 01:00:41

When you kick a ball, you don't spin it forward directly with your feet - you push it. So try "pushing" the ball with a force rather than some torque.

Also; you could experiment with mass and angular damping to make it slow down as much as you wish.

Fred

25-08-2008 11:27:09

Thank you.
I have just played with some parameters and it looks much better now. But a problem is that my sphere almost stops to rotate if I release the key, but it stops moving very slow.
My Code:

// Spieler wird durch Mausbewegung gedreht
m_pBody->setAngularVelocity(m_Steering);
// Spieler bewegen
Ogre::Vector3 rolling = Ogre::Vector3::ZERO;
if(m_Thrust.z == 1)
rolling = Ogre::Vector3(1, 0, 0);
if(m_Thrust.z == -1)
rolling = Ogre::Vector3(-1, 0, 0);
if(m_Thrust.x == 1)
rolling = Ogre::Vector3(0, 0, -1);
if(m_Thrust.x == -1)
rolling = Ogre::Vector3(0, 0, 1);

m_pBody->addForce(m_Thrust * 3000.0f);
m_pBody->addTorque(rolling * 500000.0f);

//m_pBody->setAngularDamping(0.5);
m_pBody->setLinearDamping(0.5);

If the key is released m_Thrust is set on (0,0,0) and so also rolling will set on (0,0,0). But why the sphere doesn't stay rotating for a short time?

betajaen

25-08-2008 13:00:48

Try reducing the angular damping to next to nothing and slowly decrease the mass until you have the right effect. That's all I can think of really.