Character

cyberpunkpor
Posts: 4
Joined: Wed Dec 19, 2007 10:53 am

Character

Post by cyberpunkpor »

Hi

i am trying to make my character rotate, run and walk using bullet.

I know that the a character controller is to be released, but i would appreciate you if you can help me translate this ODE implementation to bullet:

http://www.ogre3d.org/wiki/index.php/Og ... _Character

Or
if you have any demo/paper/article you can share it with me. I just want a simple way to walk, run and rotate.

My game is pretty well integrated, using a physics manager that updates the nodes (Irrlicht) position etc. My main problem, is the physics part of the player (rotation, velocity etc.). You can see the demo on the ball here:

http://video.google.com/videoplay?docid ... 3396&hl=en


Any help will be very appreciated.

Thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Character

Post by Erwin Coumans »

cyberpunkpor wrote:Hi

i am trying to make my character rotate, run and walk using bullet.

I know that the a character controller is to be released, but i would appreciate you if you can help me translate this ODE implementation to bullet:

http://www.ogre3d.org/wiki/index.php/Og ... _Character
It seems to use a dynamic rigid body using a capsule standing on a sphere. You could also use a capsule standing on a raycast.
You can use the Bullet btHingeConstraint, and set the angularOnly mode to true:

Code: Select all

hinge->setAngularOnly(true).
Such hinge also helps keeping a character facing upwards when using a rigid body with just a capsule shape.
As a start, you could try to set linear velocity on the character. Still, it will be tricky to gain full control of the motion.

That is why many approaches don't use dynamic rigid bodies to simulate characters, but kinematic objects. This means you don't take mass and forces into account at all, so that you keep full control.

For the time being, could you try just using a capsule rigid body in combination with an 'angular only' hinge? Another option is to cancel angular effects during rigid body interactions (sliding against walls etc), by using

Code: Select all

rigidbody->setAngularFactor(0.0);
You can combine this with the angular-only hinge.

Hope this helps,
Erwin
cyberpunkpor
Posts: 4
Joined: Wed Dec 19, 2007 10:53 am

Re: Character

Post by cyberpunkpor »

Thanks for helping out.
It seems to use a dynamic rigid body using a capsule standing on a sphere. You could also use a capsule standing on a raycast.
I am a newbie, so I am starting with a capsule:

Code: Select all

		
              Physics::Instance().GetBulletTransform(Transform, TObject.Position, TObject.Rotation);
		MotionState = new btDefaultMotionState(Transform);

		Shape = new btCapsuleShape(TObject.Radius,1.8f-2.0f*TObject.Radius);

		// Calculate inertia
		btVector3 LocalInertia;
		Shape->calculateLocalInertia(TObject.Mass, LocalInertia);

		RigidBody = new btRigidBody(TObject.Mass, MotionState, Shape, LocalInertia);
		RigidBody->setUserPointer((void *)this);
		RigidBody->setAngularFactor(0.0f);

		Physics::Instance().GetWorld()->addRigidBody(RigidBody, TObject.CollisionGroup, TObject.CollisionMask);
		RigidBody->setActivationState(DISABLE_DEACTIVATION);
Then i have an event that hooks for keyboard events and i just apply:

Code: Select all

		btVector3 EulerRotation;
		btQuaternion RigidRotation = RigidBody->getOrientation();
		Physics::Instance().QuaternionToEuler(RigidRotation, EulerRotation);

		RigidBody->setAngularVelocity(EulerRotation * btVector3(10*cos(1.0f),0,10*sin(1.0f)));
Then the loop will call a method that updates the node position:

Code: Select all

	// Position
	btPoint3 Point = RigidBody->getCenterOfMassPosition();
	Node->setPosition(vector3df((f32)Point[0], (f32)Point[1], (f32)Point[2]));
	
	// Rotation
	btVector3 EulerRotation;
	btQuaternion RigidRotation = RigidBody->getOrientation();
	Physics::Instance().QuaternionToEuler(RigidRotation, EulerRotation);
	Node->setRotation(vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));

	// Note changes
	if(!MovementChanged && (PreviousPosition != Node->getPosition() || PreviousRotation != Node->getRotation()))
		MovementChanged = true;

	PreviousPosition = Node->getPosition();
	PreviousRotation = Node->getRotation();
	Node->updateAbsolutePosition();

Why the player is not moving or rotating? any clues?

Note that my ball (sphere) is just other object, that inherits from the same class as the class representing my player, so the problem must be the physics / math... :cry:

thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Character

Post by Erwin Coumans »

If you choose to use a dynamic rigid body (with positive mass), you better control the character by setting the velocity, and not the position.

Also, make sure to disable deactivation (sleeping):

Code: Select all

rigidbodyCharacter->setActivationState(DISABLE_DEACTIVATION);
Hope this helps,
Erwin
cyberpunkpor
Posts: 4
Joined: Wed Dec 19, 2007 10:53 am

Re: Character

Post by cyberpunkpor »

Thanks for replying.

SetLinearVelocity can actually move the capsule, but how do I rotate by the X axis, for example and at the same time applying the velocity?
shogun
Posts: 34
Joined: Tue Mar 04, 2008 3:16 pm

Re: Character

Post by shogun »

Erwin Coumans wrote:It seems to use a dynamic rigid body using a capsule standing on a sphere. You could also use a capsule standing on a raycast.
I really wonder how this would be done ... I didn't find anything useful in the API and the demos, probably because they are pretty confusing for a newbie. ;)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Character

Post by Erwin Coumans »

Please check Bullet 2.67 Demos/CharacterDemo. That uses a dynamic rigidbody character.

For next Bullet versions we plan on adding a pure kinematic (non-dynamic) character controller, based on the btCollisionWorld::convexSweepTest.

Thanks,
Erwin
shogun
Posts: 34
Joined: Tue Mar 04, 2008 3:16 pm

Re: Character

Post by shogun »

Hello,

thanks for the advice. I looked at the code (and experimented with some values), but I'm still not sure how to let the capsule stand on a raycast. Perhaps some comments in the code would help ...

Regards,
shogun
mp3butcher
Posts: 13
Joined: Wed Jun 06, 2007 8:05 am

Re: Crowd Physical Properties

Post by mp3butcher »

Hello,
I'm working on behavioral autonomous character controllers for crowd simulating during building escape, and I only use bullet for his accurate collision response whereas my octree first approach ( number of steps integration and force limits drove me mad ).
I test tour character controller and It is exactly what I have to do with my physics/behavioral control/AI modelisation stack.
The only thing i have saw is that character have air control movement that is not very physically natural feature.
A feature that would be great for my use (and certainly other's) is a character/character collision response in order to simulate crowd behaviors. How can I cheat on this deformable object collision response in bullet ( i think of an individual character property as smoothingcollision coeff that pounder the force response between characters )?
Can it be done by a usercollision algorithm ? and if it can be done is there a mean to generalize it for all other shape in the scene?
PS: I would like to introduce a physiological model of character force endurance to check when a human cant handle pression of other..if you've an idea how to extend the character controller i would be glad?
DDd
Posts: 1
Joined: Wed Mar 26, 2008 1:37 am

Re: Character

Post by DDd »

Can i feed motion capture/keyframed data to the static character controller?

What i am thinking is that it may be possible to use the character controller to switch between motion data and ragdoll mode using a blend mode... basically the motion data defines the armature for the animation and the animation is interlaced with dynamic data in regular intervals. Do you think this could be a possibility?