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
Raycast vehicle tilts when turning right or left
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: Raycast vehicle tilts when turning right or left
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:
Cheers,
Ola
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));
Ola
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Raycast vehicle tilts when turning right or left
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.
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.
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Raycast vehicle tilts when turning right or left
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
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
-
- Posts: 169
- Joined: Sun Jan 14, 2007 7:56 pm
- Location: Norway
Re: Raycast vehicle tilts when turning right or left
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.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.
Cheers,
Ola
-
- Posts: 82
- Joined: Sun Apr 04, 2010 10:08 pm
Re: Raycast vehicle tilts when turning right or left
I have Z axis as up. When I set Y then I got bad result. Negative value was also not what I was expecting.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
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;
}
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.