Page 1 of 1
Raycast vehicle tilts when turning right or left
Posted: Fri Apr 09, 2010 1:09 pm
by razer
I coded demo program with RaycastVehicle based on Demo project from bullet.
It uses Z as up.
When I drive car and press left then car turns left as it should and tilts left like bike or bicycle but car must tilt right instead of left.
How tilt controlled?
Thanks
Re: Raycast vehicle tilts when turning right or left
Posted: Fri Apr 09, 2010 6:37 pm
by ola
Your center of gravity is set too low (it's below the ground). Move it up and you will get the effect you want.
In the vehicle demo VehicleDemo.cpp, this happens on line 310:
Code: Select all
//localTrans effectively shifts the center of mass with respect to the chassis
localTrans.setOrigin(btVector3(0,0,1));
Cheers,
Ola
Re: Raycast vehicle tilts when turning right or left
Posted: Fri Apr 09, 2010 7:14 pm
by razer
Thank You! But it does not help.
I made it
localTrans.setOrigin(btVector3(0,0,2.0f));
localTrans.setOrigin(btVector3(0,0,5.0f));
localTrans.setOrigin(btVector3(0,0,10.0f));
It always tilts as before.
Re: Raycast vehicle tilts when turning right or left
Posted: Fri Apr 09, 2010 11:41 pm
by razer
I have to change
float connectionHeight = 1.2f;
to
float connectionHeight = 1.2f / 2;
from Vehicle demo used to add Wheel
m_vehicle->addWheel
It moved box and it tilts as it should.
I thought smaller connectionHeight should move center mass down.
It works not good as it should but it is progress.
Thanks
Re: Raycast vehicle tilts when turning right or left
Posted: Sun Apr 11, 2010 9:47 am
by ola
razer wrote:Thank You! But it does not help.
I made it
localTrans.setOrigin(btVector3(0,0,2.0f));
localTrans.setOrigin(btVector3(0,0,5.0f));
localTrans.setOrigin(btVector3(0,0,10.0f));
It always tilts as before.
The z-axis is positive downwards, so you need to try 0.0 or a negative value. The 1.0 value sets the center of gravity one meter below.
Cheers,
Ola
Re: Raycast vehicle tilts when turning right or left
Posted: Sun Apr 11, 2010 3:33 pm
by razer
ola wrote:
The z-axis is positive downwards, so you need to try 0.0 or a negative value. The 1.0 value sets the center of gravity one meter below.
Cheers,
Ola
I have Z axis as up. When I set Y then I got bad result. Negative value was also not what I was expecting.
BTW I have a bit upgraded my car and set convex cast instead of ray cast %)
Code: Select all
class btConvexVehicleRaycaster : public btVehicleRaycaster
{
btDynamicsWorld* m_dynamicsWorld;
btConvexShape* m_convexShape;
btScalar m_wheelRadius;
public:
btConvexVehicleRaycaster(btDynamicsWorld* world, btConvexShape* convexShape, btScalar wheelRadius)
:m_dynamicsWorld(world), m_convexShape(convexShape), m_wheelRadius(wheelRadius)
{
}
virtual void* castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result);
};void* btConvexVehicleRaycaster::castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result)
{
// RayResultCallback& resultCallback;
btVector3 v1 = to - from;
btScalar length = v1.length();
length -= m_wheelRadius;
v1.normalize();
v1 *= length;
btVector3 to1 = from + v1;
btCollisionWorld::ClosestConvexResultCallback convexCallback(from,to1);
btTransform trFrom; trFrom.setIdentity(); trFrom.setOrigin(from);
btTransform trTo; trTo.setIdentity(); trTo.setOrigin(to1);
m_dynamicsWorld->convexSweepTest(m_convexShape, trFrom, trTo, convexCallback);
if (convexCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(convexCallback.m_hitCollisionObject);
if (body && body->hasContactResponse())
{
result.m_hitPointInWorld = convexCallback.m_hitPointWorld;
result.m_hitNormalInWorld = convexCallback.m_hitNormalWorld;
result.m_hitNormalInWorld.normalize();
result.m_distFraction = convexCallback.m_closestHitFraction;
return body;
}
}
return 0;
}
wheelRadius is wheelWidth / 2.0 (wheelRadius must be called radius. That name is my mistake)
It was advised in Google Document written by Kester Maddock to use convex. (I use sphere instead of torus.)
Ray may fall in cracks.
May car was stumbling and jumping at some point unpredictably. (It happens rare but is happens)
Convex does not fix that for me.
Damp helps but in general springs are not reliable for high speeds.
May be there should be added another force that will compensate such erroneous outbursts. Not sure how to formalize them.