Character Movement[N00B]

frier

16-07-2007 01:08:12

Ive been looking at a fair bit of code over the forums and ive trying to determine what code i would need for my game and what on top of that i will need.

I'm trying to move my character simply with NxOgre, I've seen code like this:

if (input->isKeyDown (OIS::KC_W)) {
mCharacter->addMovement(mCharacter->DR_Forward);
}


I'm just wondering whats the best way to move my character in the game?

Is this the only way? how do i make it go faster?

my game will be a game similar to mario cart, so racing etc.

p.s. Useing NXOGRE 0.9 in my game.

ANdys

16-07-2007 06:53:03

maybe here can helps you~
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=4300 :P

frier

16-07-2007 09:37:58

Oh yeah saw this before and thought it might of been redundant since its a few months old.

But ill give it ago now! Thanks Andys! ;)

frier

16-07-2007 11:38:00

Ok Regarding that link.

I've created that myCharacterMovement class and overloaded the move function.

betajaen says to move the line CharacterMovementVectorController* mMoveVectorController;

Can i use this setMovementVectorController function?
mCharacter->setMovementVectorController(new myCharacterMovement() );

So is this some sort-of Character class internal property that dictates how the character will move when i do a command like this?

if (input->isKeyDown (OIS::KC_W)) { mCharacter->addMovement(mCharacter->DR_Forward);

frier

17-07-2007 04:49:30

When i try to do the following code:


mCharacter->createNode();
mMainNode = mCharacter->getNode();

...

if(mouse->getMouseState().X.rel != 0)
mCharacter->getNode()->yaw(Radian(-(mouse->getMouseState().X.rel) * elapsedTime)/2);


When i move the mouse it starts to rotate the nodes and entity then it, i guess it hits the next frame it rotates back to its original position.

It just started doing this when i introduced the NxOgre::Player property, and the node from the character. Worked before fine.

Anyone know why it would do this?

Aiursrage2k

17-07-2007 07:35:23

You are rotating the ogre node, on the next frame it will call the render method which puts the ogre node back to the characters position and orientation. You have not changed the characters orientation so its going to "rotate back to its original position".

Look at the render function

//its puts the nodes position and orientation back to the characters position and orientation
void Character::render(float) {
if (mNode) {
mNode->setPosition(getGlobalPosition());
mNode->setOrientation(getGlobalOrientation());
}
}


Instead of that try calling setDirection function

frier

17-07-2007 08:12:04

ok i used this code:

mCharacter->setDirection(Radian(-(mouse->getMouseState().X.rel) * elapsedTime)/2);

And it still does the same thing. hmm

betajaen

17-07-2007 09:20:34

Try the code I use

Quaternion q;
q.FromAngleAxis(
Radian(-mouse->getMouseState().X.rel * 0.13),
mCharacter->getGlobalOrientation() * Vector3::UNIT_Y
);
q = mCharacter->getGlobalOrientation() * q;

mCharacter->setDirection(q);


And if you have a Camera attached to the node:

mCamera->pitch(Radian(Degree(-ms.Y.rel * 0.13).valueRadians()));

To look up and down.

frier

17-07-2007 09:36:26

i tried that code betajaen and it doesnt move my entity at all.
This is the code:

else if (input->isKeyDown (OIS::KC_PGUP)) {

Ogre::Quaternion q;
q.FromAngleAxis(
Radian(-mouse->getMouseState().X.rel * 0.13),mCharacter->getGlobalOrientation() * Vector3::UNIT_Y);
q = mCharacter->getGlobalOrientation() * q;

mCharacter->setDirection(q);

Ogre::LogManager::getSingletonPtr()->logMessage("*************");
Ogre::LogManager::getSingletonPtr()->logMessage(Ogre::StringConverter().toString(q));
//Ogre::LogManager::getSingletonPtr()->logMessage(Ogre::StringConverter().toString(mCharacter->getGlobalOrientation()));

}


This is what the quaternion value of 'q':

18:33:45: *************
18:33:45: 1 0 0 0
18:33:45: *************
18:33:45: 1 0 0 0
18:33:45: *************
18:33:45: 1 0 0 0
18:33:45: *************
18:33:45: 1 0 0 0
18:33:45: *************
18:33:45: 1 0 0 0

betajaen

17-07-2007 10:55:41

Have you tried to see what the value of "-mouse->getMouseState().X.rel" is?

frier

17-07-2007 12:59:02

Shit i see what i did wrong!, thanks betajaen and the fonz!.

I gota stop coding after i get back from training. to many head kicks :<