Big problem, Character Movement

l34ndr4

09-03-2006 12:22:04

Hi, we have a big problem
moving the a character with forces.
we are making an FPS character , so the character should
stop when the key is released.
we have read all about inverse dynamics in the newton forums
and everywhere but it doesnt work (for us) :S
the player moves right but the aceleration decrements slowly.
this is our code in the forcecallback.

Real desiredVelocity = 0.001;
Vector3 V0 = me->getVelocity();
Vector3 V1=player->getVectorDirection()*player->getVectorDirection().normalise();
V1=V1*desiredVelocity;

Vector3 acel ((V1 - V0) / 1);

acel = acel * 0.3f;

Vector3 force = Vector3(acel.x,-9.8,acel.z)/1000 * mass;

me->addForce(force);


//explanation
we are just passing this newton code to ogrenewt
http://www.physicsengine.com/forum/viewtopic.php?t=342

the / 1 its because we are just assuming that every time it is called it has pass a second.

the /1000 its because the resulting aceleration its to big so we have to narrow it down.

the getVectorDirection() function just gives us the player direction * camera orientation.

pls can someone tell me whats wrong with my code.
thx in advance.

btw:: my friction between the 2 materials is 0,0 or BIG#,BIG# and really havent seen much difference.

Horizon

09-03-2006 13:16:45

Please, this is kind of hard on the eyes. Format it like this:

Hi, we have a big problem moving the a character with forces. we are making an FPS character , so the character should stop when the key is released. we have read all about inverse dynamics in the newton forums and everywhere but it doesnt work (for us) :S the player moves right but the aceleration decrements slowly. this is our code in the forcecallback.

Real desiredVelocity = 0.001;
Vector3 V0 = me->getVelocity();
Vector3 V1=player->getVectorDirection()*player->getVectorDirection().normalise();
V1=V1*desiredVelocity;

Vector3 acel ((V1 - V0) / 1);

acel = acel * 0.3f;

Vector3 force = Vector3(acel.x,-9.8,acel.z)/1000 * mass;

me->addForce(force);


//explanation
we are just passing this newton code to ogrenewt http://www.physicsengine.com/forum/viewtopic.php?t=342. the / 1 its because we are just assuming that every time it is called it has pass a second. the /1000 its because the resulting aceleration its to big so we have to narrow it down. the getVectorDirection() function just gives us the player direction * camera orientation. pls can someone tell me whats wrong with my code. thx in advance.

btw:: my friction between the 2 materials is 0,0 or BIG#,BIG# and really havent seen much difference.

walaber

09-03-2006 16:00:41

it doesn't work because you are assuming a full second has elapsed! that's ridiculous!

to get the timestep from inside the callback, please do this:
Ogre::Real deltatime = body->getWorld()->getTimeStep();

l34ndr4

10-03-2006 02:09:38

thanx WALABER :D
it work like a charm, my player moves great,

I need 2 more fixes and I have finished my movement.

for the torque so that my box rotates like my mouse I have to give it a torque in Y, right now it does it but , its like the force before it doesnt stop so here's what Im doing...


Real desiredRotation = 100;
Vector3 V2 = me->getOmega();
Vector3 V3=player->orientation*player->orientation.normalise();
V3=V3*desiredRotation;
Vector3 rot ((V3 - V2) / me->getWorld()->getTimeStep());
rot = rot * 0.3f;
Vector3 torque = Vector3(0,rot.x,0) * mass;
me->addTorque(torque);



where player->orientation is = Camera->getOrientation() * Vector3::UNIT_SCALE;

and I have to do half a twist so that the torque comes back again .....
sry for bodering but my physics are really crappy..

and another thing for the jump im doing this in


keydown(KC_SPACE)
body->addImpulse(Vector3(0,100,0),Vector3::UNIT_Y);


but in my force callback I have the upvector


Vector3 upDirection (0.0f, 1.0f, 0.0f);
NewtonConstraintCreateUpVector(me->getWorld()->getNewtonWorld(), &upDirection.x, me->getNewtonBody());


so it looks like it anulates the impulse and the character doesnt jump,
so dont know how to fix this....

walaber

10-03-2006 04:24:41

please read the documentation about the addImpulse function, you are using it wrong.

l34ndr4

10-03-2006 16:49:26

hi, I maked the torque work :D

I have read the Docs but didnt understand it well :?

For my jump , the addimpulse its forking find if my character is in the air
before ir collides, but when he collides it doesnt work,

so im stuck in that, can u explain me a little bit more how to use the add impulse pls

walaber

10-03-2006 17:09:25

you pass a change in velocity to a point in global space. for jumping, do something like this:


Ogre::Vector3 bodyPos;
Ogre::Quaternsion bodyOrient;

playerBody->getPositionOrientation( bodyPos, bodyOrient );

playerBody->addImpulse( Ogre::Vector3(0,10,0), bodyPos );

l34ndr4

11-03-2006 19:57:27

its working find now , thx im learning a LOT.....

btw now I find a new problem :?

Im making collisionPairs with different objects and im inserting the
default friction diferent for my objects,

but for my player(sphere) and my ground(treeCollision)
the default friction has to be 0,0 so that my player doesnt act like a real sphere(rolling) .

but it seems that i just can put a default friction to the world instead of each pair individually it only takes the first one, the box and the floor has the friction of the player and the floor and dont know why

heres my code


MaterialPair* collisionRule = new MaterialPair(m_World,getMaterialID("player"),getMaterialID("floor"));
collisionRule->setContactCallback( this );
collisionRule->setDefaultFriction( 0,0 );

MaterialPair* collisionRule2 = new MaterialPair(m_World,getMaterialID("box"),getMaterialID("floor"));
collisionRule2->setContactCallback( this );
collisionRule2->setDefaultFriction( 2,2 );

:?

walaber

11-03-2006 20:59:56

pleaaaaaaseeee look at the demos. for materials you need to create them yourself!

if you want 3 total materials, you can use the default material, but you will need to create 2 more NEW materials, and then set the behavior between them.

l34ndr4

11-03-2006 21:22:08

sry i forgot
yes i have created my materials
like this I have a array of materials
so i have 3 materials
called ,player , box, and floor.
and i create them like this.

matPlayer.material =new MaterialID(m_World);
matPlayer.name="player";
matBox.material =new MaterialID(m_World);
matBox.name ="box";
matFloor.material =new MaterialID(m_World);
matFloor.name ="floor";

and my function getmaterialID(name) brings my back the mateial..

walaber

11-03-2006 21:47:47

are you properly applying the MaterialID's to the individual bodies?

please explain the problem exactly... I'm having trouble understanding your explanation.


are you saying that box vs. floor also have no friction even though you set it to (2,2) ?

l34ndr4

13-03-2006 12:18:58

hi, thx for the help it was my problem :P

my getMaterialId wasnt giving my the correct material :P

thx.