KinimaticController can push RigidBody into static Object

H3g3m0n
Posts: 2
Joined: Wed May 13, 2009 8:31 am

KinimaticController can push RigidBody into static Object

Post by H3g3m0n »

I am currently making a game engine for my Uni course.

For now I have a simple game where the character pushes boxes around (basically Sokoban in 3D), however the boxes can sometimes be pushed into the wall, when the character backs off they will pop out again.

I have setAngularFactor(0.0) set on the boxes to stop them rotating, and the walls are RigidBodies with a mass of 0, so they are exactly flat on to each other.

Theres a lot of code so I can't really post it here.

This is my main update loop function called from my game (the time is SDL_GetTicks() rather than the bullet one, I don't know if thats likely to case anything odd.). I'm not too sure if this is the best way to update it, ive seen posts talking about fixed frequency ones and I can see that the physics outcome might be based on the framerate.

Code: Select all

/**
 * updates the physics based on the time.
 * @param time The current game time in milliseconds.
 */
void Physics::update(const int time) {
	int time_diff = time - getLastupdate();
	if(time_diff <= 0) {
		return;
	}
	btScalar timeStep = ((float)time_diff) / 1000.0f;
	int numsimsteps = dynamicsWorld_->stepSimulation(timeStep,0,1.0/60.0);
	Updateable::update(time); // Just sets the value for getLastUpdate.
}
This is where I initialize the bullet stuff.

Code: Select all

Physics::Physics() {
	body_max_ = 16384; /* Maximum number of rigid bodies */

	btVector3 worldAabbMin(-10000,-10000,-10000);
	btVector3 worldAabbMax(10000,10000,10000);

	broadphase_ = new btAxisSweep3(worldAabbMin,worldAabbMax,body_max_);
	collisionConfiguration_ = new btDefaultCollisionConfiguration();
	dispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
	solver_ = new btSequentialImpulseConstraintSolver;

	dynamicsWorld_ = new btDiscreteDynamicsWorld(dispatcher_,
					broadphase_, solver_, collisionConfiguration_);
	setGravity(GRAVITY_EARTH);

	gDebugDrawer_.setDebugMode(1);
	dynamicsWorld_->setDebugDrawer(&gDebugDrawer_);
	body_count_ = 0;
}
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: KinimaticController can push RigidBody into static Object

Post by AlexSilverman »

While the behavior you're seeing might not be desired, it's not technically wrong. A Kinematic object is a type of static object, and it will not get pushed around by any dynamic objects, so the dynamic boxes in your scene will respond no matter how far into the wall. We used a sphere for our character controller, as we just needed a simple object to keep the player from running through things. Applying forces based on input worked out just fine for us, keeping us in bounds, and also allowing the player to knock things around.

- Alex