characters moving at strange speeds

jchmack

01-05-2007 12:39:01

Ever since i upgraded to 0.6 my characters move faster at slower framerates and vice versa. At first i thought it must be me but i still can't find a solution. It worked fine before the upgrade but now... I believe that before i was using 0.3 i skipped 0.4 and just upgrade to eihort/0.6/VSSP1 all at once.

Does anyone else have similar problems?

how i make my character

void GameCharacter::Create(scene *mScene,Vector3 InitialPosition)
{
name+=Ogre::StringConverter::toString(objectcount);
objectcount++;

blueprint<character> bp;
bp.setToDefault();
bp.setGravity(false);
bp.setSlopeLimit(45);
bp.setStep(0.3);
bp.setShapeAsCapsule(CharacterRadius,CharacterHeight);
bp.setMesh("");

mCharacter = bp.create(name,InitialPosition,mScene);

//mPlayer->mController->
//mBody->setGroup(mScene->findGroup("Projectiles"));

PivotNode= mCharacter->mNode->createChildSceneNode(name+"Pivot Node");

MeshNode = mCharacter->mNode->createChildSceneNode(name+" Mesh Node");
MeshEntity = mScene->mSceneMgr->createEntity(name+" Entity",mesh);
MeshNode->translate(Vector3(0,-((CharacterHeight/2)+CharacterRadius),0));
MeshNode->scale( Vector3(1,1,1)*NinjaMeshConverter*(CharacterHeight+2*(CharacterRadius)));
MeshNode->attachObject(MeshEntity);

CharacterCamera = mScene->mSceneMgr->createCamera(name+" Camera");
CharacterCamera->setNearClipDistance(0.1);
//CharacterCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight()));

//CharacterCamera->moveRelative(Vector3(0,.1,-CharacterRadius));
CharacterCamera->moveRelative(Vector3(0,10,10));
CharacterCamera->pitch(Degree(-30));
//CharacterCamera->setAutoTracking(true,mPlayer->mNode);

mCharacter->mNode->attachObject(CharacterCamera);

GunNode = PivotNode->createChildSceneNode(name+" Gun Node");
GunNode->translate(Vector3(0,0,-(CharacterRadius+0.01)));

Entity* GunNodeEntity = mScene->mSceneMgr->createEntity(name+"GunNode CrossHairs", "nx.crosshair.mesh");
GunNode->attachObject(GunNodeEntity);
GunNode->scale(5,5,5);
}


functions i use to move him


void GameCharacter::ChangeMovestate(MoveState _mMoveState)
{
mMoveState=_mMoveState;
}


void GameCharacterManager::MoveCharacter(list<GameCharacter*>::iterator Character)
{
//mNetworkMgr->
switch((*Character)->mMoveState)
{
case BackwardLeft:
(*Character)->mCharacter->move(character::BACKWARD);
(*Character)->mCharacter->move(character::SIDESTEP_LEFT);
break;

case Backward:
(*Character)->mCharacter->move(character::BACKWARD);
break;

case BackwardRight:
(*Character)->mCharacter->move(character::BACKWARD);
(*Character)->mCharacter->move(character::SIDESTEP_RIGHT);
break;

case Left:
(*Character)->mCharacter->move(character::SIDESTEP_LEFT);
break;

case Neutral:
break;

case Right:
(*Character)->mCharacter->move(character::SIDESTEP_RIGHT);
break;

case ForwardLeft:
(*Character)->mCharacter->move(character::FORWARD);
(*Character)->mCharacter->move(character::SIDESTEP_LEFT);
break;

case Forward:
(*Character)->mCharacter->move(character::FORWARD);
break;

case ForwardRight:
(*Character)->mCharacter->move(character::FORWARD);
(*Character)->mCharacter->move(character::SIDESTEP_RIGHT);
break;

default:
break;

}
}



from where i call



MoveState temp;
short int x=0,z=0;

if (isKeyDown(Z))
++z;
if (isKeyDown(NEG_Z))
--z;
if (isKeyDown(X))
++x;
if (isKeyDown(NEG_X))
--x;

if(z>0) //forward
{
if(x>0)
temp=ForwardLeft;
else if (x<0)
temp=ForwardRight;
else
temp=Forward;
}
else if (z<0) //backward
{
if(x>0)
temp=BackwardLeft;
else if (x<0)
temp=BackwardRight;
else
temp=Backward;
}
else //neutral
{
if(x>0)
temp=Left;
else if (x<0)
temp=Right;
else
temp=Neutral;
}

if(character1->mMoveState!=temp)
{
character1->ChangeMovestate(temp);

if(mNetworkMgr.connected==true)
mNetworkMgr.SendCharacterMove(character1);
}



basically i create him. When a key is pressed i change his movestate. Every frame i call movecharacter() which calls mCharacter->move() in the appropriate direction depending on the movestate. Its all pretty basic stuff.

on a side note if your wondring why i use the whole movestate thing its for networking purposes. So i can just send a movestate along with a position.

sorry if the code is excessive but ive been looking over this for a while. Its basically derived from tutorial 606. I don't know why it would do this..
Im betting that i need to scale the movement by the time SOMEWHERE.

Im starting to think it might be an NXOgre issue but i have to admit i haven't really looked at the NXOgre source yet. Figured id ask here first. Thanks to all who help in advance :D

edit: by the way im running it in:
release mode
NXOgre 0.6
PhysX 2.7.0
Eihort

links for my research purposes:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3932
http://www.ogre3d.org/phpBB2addons/view ... d673edd8fc

betajaen

01-05-2007 17:08:37

I only briefly read your code, but it seems your using deltaTime with the movement vector.

Roughly:
float deltaTime = evt.timeSinceLastFrame;
Vector3 movementVector;

if (Backward)
movementVector += Character::BACKWARD;


mCharacter->move(movementVector * deltaTime);



You could also turn on VSync and set the PhysX iterator to a fixed one, operating every 1.666 times a second. I can show you the code for that if you like.

jchmack

02-05-2007 15:06:05

I thought that NXOgre automatically accounted for the framerate and It factored in the Deltatime for me? Shouldn't i just have to call Move(direction) each frame? Ive been messing around with Deltatime but i can't get the desired effect.

But as for the VSYNC thing im not exactly sure what it is or how to do it...

betajaen

02-05-2007 15:10:10

It should do.

VSync is an option in the render settings. You can see it in the window that pops up when you launch an Ogre application. Basically it limits the maximum frames per second to 60.

jchmack

02-05-2007 15:14:16

I am not exactly sure what you are reccomending i do?

there is no character->move() that takes a vector3 as a parameter:

1>.\GameCharacterManager.cpp(52) : error C2664: 'nxOgre::character::move' : cannot convert parameter 1 from 'Ogre::Vector3' to 'nxOgre::character::Direction'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

so im not exactly sure where you are reccomending i should scale the movement...

also how do i enable VSYNC?

betajaen

02-05-2007 15:22:48

Right. When I said that I didn't have a copy of the source on me as I'm working on a computer without Ogre or NxOgre on it. I'm looking at the SVN now, and your right it does take the deltaTime in account for you.

Easiest way to enable VSync is to select the option in the settings window. (Click VSync then Yes), or a more permeant way is to pass it on as a configuration option to the rendersystem when you set up your window and such. It's a little complicated to do so. The NxOgre tutorials actually do this, and you can see it from there.

I would also switch the PhysX iterator to fixed:
mScene->setTiming(Scene::FIXED, 1.0f / 60.0f, 8);

Unfortunately; the Character Controller and WheelShape are the two systems in PhysX which bend the laws of physics as it were, and a pain to get it working properly in a realistic way.

jchmack

02-05-2007 15:36:28

well i tried the fixed step and it looks about the same...

Unfortunately; the Character Controller and WheelShape are the two systems in PhysX which bend the laws of physics as it were, and a pain to get it working properly in a realistic way.

True... what you are doing is really complicated. But i'm figuring that since no one else seems to be having similar problems with 0.6 it must be something on my end. And from what im seeing im doing exactly what the tutorials do. Sigh... i guess ill just have to keep looking. Well thanks for your insights. If anyone else is having similar problems PLEASE do tell lol.

edit: @betajaen did you change alot (in the character system) from 0.3 to 0.4 to 0.6? the reason i ask is because i didn't have this problem in 0.3. The 0.3 characters were alot worse when dealing with stairs and dynamic bodies and the 0.6 characters seem perfect except for this problem.

betajaen

02-05-2007 15:50:21

I'm hoping it'll be different in 0.9, which the SVN link will be released to the public. You can wait until then, or just fiddle around in then.

What you could try; Is "limit" the amount of walking/running movement in a second. Just get the magnitudes of the last second and this second vector and compare.