btRaycastVehicle just won't move

Nanocinder
Posts: 2
Joined: Wed Oct 03, 2012 3:00 pm

btRaycastVehicle just won't move

Post by Nanocinder »

I am really struggling with creating a vehicle using Bullet. I have gone through the VehicleDemo and done everything as they have except tried replacing values with my own vehicle dimensions.
However, I just cannot get it to move, might be something to do with the connection points of the wheels or something.

Code: Select all

        btVector3 inertia;
	btTransform shift(btQuaternion::getIdentity(), btVector3(0.f, 0.55f, 0.f));
	btCollisionShape* boxShape = new btBoxShape(btVector3(4.f, 3.f, 10.f));
	btCompoundShape* chassisShape = new btCompoundShape();
	chassisShape->addChildShape(shift, boxShape);
	chassisShape->calculateLocalInertia(mChassisMass, inertia);
	btTransform trans(btQuaternion::getIdentity(), btVector3(0,0,0));
        btDefaultMotionState* motionState = new btDefaultMotionState(trans);

	mCarBody = new btRigidBody(mChassisMass, motionState, chassisShape, inertia);
	mCarBody->translate(btVector3(0, 7, 0));
	world->addRigidBody(mCarBody);
	mCarBody->setDamping(mChassisLinearDamping, mChassisAngularDamping);
        mCarBody->setActivationState(DISABLE_DEACTIVATION);

        mTuning.m_frictionSlip = mWheelFriction;
        mTuning.m_maxSuspensionForce = mMaxSuspensionForce;
        mTuning.m_maxSuspensionTravelCm = mMaxSuspensionTravelCm;
        mTuning.m_suspensionCompression = mSuspensionCompression;
        mTuning.m_suspensionDamping = mSuspensionDamping;
        mTuning.m_suspensionStiffness = mSuspensionStiffness;

        mVehicleRaycaster = new btDefaultVehicleRaycaster(world);
        mVehicle = new btRaycastVehicle(mTuning, mCarBody, mVehicleRaycaster);
        mVehicle->setCoordinateSystem(0, 1, 2); // rightIndex, upIndex, forwardIndex

        float mSuspensionRestLength = 0.5f;
        float mConnectionHeight = 0.5f;
        float mWheelRadius = 1.5f;
        float wheelBaseLength = 8.f;
        float wheelBaseHalfWidth  = 3.7f;
        btVector3 wheelDirectionCS0(0,-1,0);
        btVector3 wheelAxleCS(-1,0,0);
        bool isFrontWheel = true;

    // Wheel 0 - Front Left
    btVector3 connectionPointCS0 (wheelBaseHalfWidth, mConnectionHeight, wheelBaseLength);
    mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );

    // Wheel 1 - Front Right
    connectionPointCS0 = btVector3(-wheelBaseHalfWidth, mConnectionHeight, wheelBaseLength);
    mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );

    isFrontWheel = false;
    // Wheel 2 - Rear Right
    connectionPointCS0 = btVector3(-wheelBaseHalfWidth, mConnectionHeight, -wheelBaseLength);
    mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );

    // Wheel 3 - Rear Left
    connectionPointCS0 = btVector3(wheelBaseHalfWidth, mConnectionHeight, -wheelBaseLength);
    mVehicle->addWheel( connectionPointCS0, wheelDirectionCS0, wheelAxleCS, mSuspensionRestLength, mWheelRadius, mTuning, isFrontWheel );

    for( int i=0; i < mVehicle->getNumWheels(); i++ )
	{
		btWheelInfo& wheel                  = mVehicle->getWheelInfo( i );
		wheel.m_suspensionStiffness         = mSuspensionStiffness;
		wheel.m_wheelsDampingRelaxation     = mSuspensionDamping;
		wheel.m_wheelsDampingCompression    = mSuspensionCompression;
                wheel.m_maxSuspensionForce          = mMaxSuspensionForce;
		wheel.m_frictionSlip                = mWheelFriction;
		wheel.m_rollInfluence               = mRollInfluence;
	}
    world->addVehicle(mVehicle);
I apologise for the amount of code. I'm just really struggling to find out why it won't move and hoped someone might see something that was obviously wrong.

Thanks.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: btRaycastVehicle just won't move

Post by Mako_energy02 »

May or may not be the issue, but I noticed in your code you are adding to the world with "addVehicle" function call. The api doc's says that method is obsolete and you should use the "addAction" method instead.

Edit: Just checked the source, and internally it calls that method itself. So I guess that wouldn't matter. =\
craftit
Posts: 1
Joined: Thu Oct 04, 2012 12:29 pm

Re: btRaycastVehicle just won't move

Post by craftit »

I'm having the same problem.

I think its because I set it up using btStaticPlaneShape for the ground.

See http://bulletphysics.org/mediawiki-1.5. ... p/Vehicles
Nanocinder
Posts: 2
Joined: Wed Oct 03, 2012 3:00 pm

Re: btRaycastVehicle just won't move

Post by Nanocinder »

Thanks very much! I have switched it to addAction even though that wasn't the cause.
I am using a btBoxShape for the ground, so I don't think it is that.

This is really irritating! If the wheels are incorrectly positioned or the parameters wrong, would that cause the vehicle to just not move, or should you at least some form of strange incorrect movement?

*EDIT* When I made suspension rest length much longer it started moving, however, when it moves, it is all jittery with its movement.
It's tough to work out the correct values without knowing what all the variables and parameters do or are for. I will try looking in the API.

*EDIT*
Incase anyone is interested, I played around with the parameters relating to wheel positioning, suspensionRestLength and connectionheight and eventually it worked. Also I had a problem with it tipping over, lowering the Roll influence variable closer to 0 stopped this happening as well.