Vehicle issues

Paril
Posts: 18
Joined: Tue Feb 22, 2011 4:14 am

Vehicle issues

Post by Paril »

Hey there.

I'm having a couple of issues with Bullet's raycast vehicle.

1) How can I simulate acceleration/top-speed values?
2) Why does turning seem to change at high speeds? Like, unrealistically?

-P
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Vehicle issues

Post by mi076 »

1) How can I simulate acceleration/top-speed values?
the easiest way to simulate acceleration is to implement somehow throttle 0.0..1.0 ( applyEngineForce(throttle*max_engine_force) )and add damping force, easiest way is just add linear damping to rigid body, but much better add air resistance...

http://en.wikipedia.org/wiki/Drag_(physics)

Code: Select all

// drag coefficient
btScalar drag_coefficient = btScalar(0.3);
  
// area of the orthographic projection of the object
// on a plane perpendicular to the direction of motion (m^2)
btScalar area = btScalar(2.2);
  
// air density (kg/m3)  
btScalar rho  = btScalar(1.22521);   
btScalar Cdrag = btScalar(0.5) * drag_coefficient * area * rho;

btVector3 linear_velocity = body->getLinearVelocity();
btVector3 Fdrag(0,0,0);
    if (!linear_velocity.fuzzyZero())
        Fdrag = -Cdrag*linear_velocity.length2()*linear_velocity.normalized();



you can not configure it currently with... it is on you own how you add it, modify btRaycastVehicle or put in your code...

Edited: ... and there are also, of course, rolling resistance and other factors..
Last edited by mi076 on Sat Mar 26, 2011 1:05 am, edited 3 times in total.
Paril
Posts: 18
Joined: Tue Feb 22, 2011 4:14 am

Re: Vehicle issues

Post by Paril »

Yeah, I was thinking about it and I figure I can just make engine force increase by a set value until it reaches maxEngineForce.

Whether this is right or not I don't know, but it seems to work; I do this to simulate a top-speed:

Code: Select all

		var spd = m_vehicle->getRigidBody()->getLinearVelocity();

		if (spd.length() > maxVehicleSpeed)
			m_vehicle->getRigidBody()->setLinearVelocity((spd / fabs(spd.length() / maxVehicleSpeed)));
The only problem I can think of is it would also affect flying through the air and things like that. Doing it based on drag might be a better idea, but I want my users to be able to enter specific top-speed values, hence why I did it this way.

-P