3rd person movement + angular velocity

teamAlpha
Posts: 6
Joined: Fri Mar 13, 2009 5:59 pm

3rd person movement + angular velocity

Post by teamAlpha »

Hi :shock: .

I've got a 3rd person movement test demo working , but i can't figure out how to apply angular
velocity.

For example , im translating my object into the world like this:

Code: Select all

	v[0] = trans.getOrigin().getX() - cosf(dir   ) * (vel * dtl);
	v[1] = trans.getOrigin().getY();
	v[2] = trans.getOrigin().getZ() - sinf(dir     ) * (vel * dt);

       //apply rotation manually here
But of course this won't let me to apply angular velocity...

I've also tried this:

Code: Select all

          body->setAngularVelocity( v/1000);
But of course it doesn't work...

So , do you guys have any ideas how to combine 3rd person movement with bullet?

Thanks for any help...
chucksspencer
Posts: 35
Joined: Wed Jun 25, 2008 2:52 pm

Re: 3rd person movement + angular velocity

Post by chucksspencer »

Are you sure you set up the local inertia? If you're not already doing this before you add the body to the world try this (where mass is a float containing the mass of your object)

Code: Select all

			btVector3 localInertia(0,0,0);
			body->getCollisionShape()->calculateLocalInertia(btScalar(mass, localInertia);
			body->setMassProps(mass, localInertia);
Also be sure to activate the shape - body->activate(true);

I hope that helps!
teamAlpha
Posts: 6
Joined: Fri Mar 13, 2009 5:59 pm

Re: 3rd person movement + angular velocity

Post by teamAlpha »

chucksspencer wrote:Are you sure you set up the local inertia? If you're not already doing this before you add the body to the world try this (where mass is a float containing the mass of your object)

Code: Select all

			btVector3 localInertia(0,0,0);
			body->getCollisionShape()->calculateLocalInertia(btScalar(mass, localInertia);
			body->setMassProps(mass, localInertia);
Also be sure to activate the shape - body->activate(true);

I hope that helps!
Really thanks for your input , but yeah , im doing all these.

My problem is that i can't find a proper way to translate my object at any angle(=based on camera's ange) using setAngularVelocity()...

And im really stuck now , since the game will be unplayable when the user rotates the camera around the object...
teamAlpha
Posts: 6
Joined: Fri Mar 13, 2009 5:59 pm

Re: 3rd person movement + angular velocity

Post by teamAlpha »

And here is some source that will help you to fully understand my case:


With this code i translate my object :

Code: Select all

	//get current transformation
	btTransform trans;
	trans.setIdentity();
	trans = m_PlayerObject.obj->body->getCenterOfMassTransform();

	//translate forward at proper event
	btVector3 v(0,0,0);
	const float  dir =  m_PlayerObject.obj->node->getRotation().Y *DEGTORAD;
				
	v[0] = trans.getOrigin().getX() - cosf( (1.f+dir)  ) * ( playerVel* dtMul);
	v[1] = trans.getOrigin().getY();
	v[2] = trans.getOrigin().getZ() - sinf( (1.f+dir)  ) * (playerVel * dtMul);

	m_PlayerObject.obj->body->setAngularFactor(-0.4f *dtMul);
	m_PlayerObject.obj->body->setCenterOfMassTransform(trans);   


This does work , but there is no way to apply "force" , so , when for example
i change the "body" pointer to a ball(= sphere) , there is no rotation at all... :-/.
chucksspencer
Posts: 35
Joined: Wed Jun 25, 2008 2:52 pm

Re: 3rd person movement + angular velocity

Post by chucksspencer »

teamAlpha wrote:And here is some source that will help you to fully understand my case:


With this code i translate my object :

Code: Select all

	//get current transformation
	btTransform trans;
	trans.setIdentity();
	trans = m_PlayerObject.obj->body->getCenterOfMassTransform();

	//translate forward at proper event
	btVector3 v(0,0,0);
	const float  dir =  m_PlayerObject.obj->node->getRotation().Y *DEGTORAD;
				
	v[0] = trans.getOrigin().getX() - cosf( (1.f+dir)  ) * ( playerVel* dtMul);
	v[1] = trans.getOrigin().getY();
	v[2] = trans.getOrigin().getZ() - sinf( (1.f+dir)  ) * (playerVel * dtMul);

	m_PlayerObject.obj->body->setAngularFactor(-0.4f *dtMul);
	m_PlayerObject.obj->body->setCenterOfMassTransform(trans);   


This does work , but there is no way to apply "force" , so , when for example
i change the "body" pointer to a ball(= sphere) , there is no rotation at all... :-/.
If I'm not mistaken, setting the angularFactor to a negative value prevents the shape from rotating.
teamAlpha
Posts: 6
Joined: Fri Mar 13, 2009 5:59 pm

Re: 3rd person movement + angular velocity

Post by teamAlpha »

chucksspencer wrote:
teamAlpha wrote:And here is some source that will help you to fully understand my case:


With this code i translate my object :

Code: Select all

	//get current transformation
	btTransform trans;
	trans.setIdentity();
	trans = m_PlayerObject.obj->body->getCenterOfMassTransform();

	//translate forward at proper event
	btVector3 v(0,0,0);
	const float  dir =  m_PlayerObject.obj->node->getRotation().Y *DEGTORAD;
				
	v[0] = trans.getOrigin().getX() - cosf( (1.f+dir)  ) * ( playerVel* dtMul);
	v[1] = trans.getOrigin().getY();
	v[2] = trans.getOrigin().getZ() - sinf( (1.f+dir)  ) * (playerVel * dtMul);

	m_PlayerObject.obj->body->setAngularFactor(-0.4f *dtMul);
	m_PlayerObject.obj->body->setCenterOfMassTransform(trans);   


This does work , but there is no way to apply "force" , so , when for example
i change the "body" pointer to a ball(= sphere) , there is no rotation at all... :-/.
If I'm not mistaken, setting the angularFactor to a negative value prevents the shape from rotating.
No , that's not the case...

I just can't find a way to do my custom translation , and then apply some force to the right angle...

In ODE for example , you can apply torque at a given point...eg : addTorque(body,x,y,z)...i can't find anything similar in bullet ...

Right now it looks like no physics applied at all :? ...
teamAlpha
Posts: 6
Joined: Fri Mar 13, 2009 5:59 pm

Re: 3rd person movement + angular velocity

Post by teamAlpha »

Never mind , found it ... I had to apply normalized central force and modify the friction & angular factor. :o