Another FPS Camera Question
almondega
17-08-2008 22:46:19
hi
i'm trying to use NxOgre in my fps game
then, i did the wasd movements, all works fine
after all, the jump code (applying a Y force)
but the character falls down with a constant speed
am i doing this wrong, re-writing a fps camera code, or there are a character class in NxOgre to do it (movements, jumps, run) ? i took a look at the NxOgreCharacterControler but didnt find anything about movements like this.
in a last hope, i went to the PhysX character sample, witch jump and fall down with acceleration, but get weird fall when just droping from a plane (like a floor above the ground)
any sugestions?
tks
mcaden
17-08-2008 22:50:39
This is a common problem, there's many threads about it on the forum, with several solutions. I think the most basic is just to apply a downward force each frame. I haven't gotten around to fixing it in my own game quite yet though. I've been working on other things.
I believe the root of the problem is that linear damping is affecting gravity.
almondega
17-08-2008 22:56:55
yes, i searched about this
and all solution was rewriting the character class (in 0.9 versions)
but there are a 1.0'21 right now, and didnt see anyone asking for it =]
also my other question is if there are a pre-made fps like camera movements (to avoid to do the same think)
but i'll do like u did, let the jump acceleration by side and do others things
mcaden
18-08-2008 03:30:03
somebody dealing with a vehicle proposed this solution:
mActor->addLocalForce(NxVec3(0, -mass, 0), NX_IMPULSE);
I haven't tried it yet but I think it looks pretty good. I believe there'll have to be an if statement making sure the downward velocity doesn't go beyond what would be considered the terminal velocity. Of course you'll have to set the mass variable above with the actor's mass.
However, I'm still learning NxOgre and my only physics education was a practical physics class (concepts, not formulas) and it's been almost 10 years since then so if I'm misleading you I apologize.
almondega
18-08-2008 03:59:53
i'll try it when i get my computer back
tks
=]
almondega
20-08-2008 02:38:05
didnt solve the problem
=\
i'll try to find another solution
mcaden
24-08-2008 08:07:20
mBody->addForce(NxVec3(0, -mBody->getMass() * 1.5, 0), NX_IMPULSE);
Worked for me.
I had to double movement forces though (forward/backward).
My jumping code:
if( !mJumping && !mDead )
{
mBody->addForce(NxVec3(0, 10000, 0), NX_FORCE);
mJumping = true;
}
If it doesn't end up how you're wanting it, tweak the numbers. If he's not jumping high enough change the "10000" in the jump code. If he's not falling fast enough change the other one change "getMass() * 1.5".
Next I was thinking about adding terrain callbacks so he can only jump when he's touching terrain. This sorta leaves holes though. (ie, means he can jump if he's touching a wall). Is there a way to tell which side of the collision box I'm hitting so I can make sure it's his feet that are touching and not his head (Rot_X and Rot_Z are frozen so if I'm using a cube in would only be if the bottom plane hit terrain)? Or will I have to make the ground a separate Collision mesh in order for this to work? (my terrain currently is a cave - static triangle mesh)
Also, if there's a better way of accomplishing this I'd love to know.
almondega
25-08-2008 22:46:50
u mean to every frame add a negative Y force to the ground?
that should work, i'll try
just another question
the camera is attached to a shape body, that receive forces
for a character, the base shape (foot) shoud be a capsule or a sphere?
and how to configure it to avoid the friction with the ground? (to have a smooth movement, not a jerky one)
tks =]
mcaden
26-08-2008 05:11:22
You mean the jitter?
About to start working on that myself. I read a bunch of posts on it. Something about it rendering 1 frame behind or skipping frames or something similar.
betajaen
26-08-2008 08:59:04
Interpolation. Luis has practically written a thesis on it.
mcaden
26-08-2008 10:04:46
I'm having it even though I've turned interpolation on.
betajaen
26-08-2008 11:13:20
With the Accumulator Scene Controller? Those two have to work together for interpolation, if that doesn't work (or doesn't help enough) - I have a third solution.
mcaden
26-08-2008 14:51:13
The applicable code lines:
mWorld = new World("use-log: yes, time-controller: ogre");
mScene = mWorld->createScene("NxScene", "renderer: ogre, controller: accumulator, gravity: yes, floor: yes");
NodeRenderableParams vp;
vp.setToDefault();
vp.mGraphicsModel = mesh;
vp.mGraphicsModelScale = NxVec3(1, 1, 1);
vp.mIdentifier = mName;
vp.mIdentifierUsage = vp.IU_Use;
vp.mMode = RenderableSource::RM_Interpolate;
mcaden
27-08-2008 16:15:40
I thought maybe it was the code Luis posted in the 1.0'21 release thread on the first page, but the code doesn't compile.
/////////////////////////////////////////////////////////////
void RenderableSource::render_Interpolate(const TimeStep& ts) {
Pose sourcePose = getSourcePose(ts);
if( ts.physicsSimulated )
mAlphaPose = sourcePose;
mRenderPose = NxInterpolate(mAlphaPose, sourcePose, ts.Alpha);
mRenderable->setPose(mRenderPose);
}
error C2039: 'physicsSimulated' : is not a member of 'NxOgre::TimeStep'
almondega
29-08-2008 02:08:45
wow
i remember to had delete the interpolate stuff cuz i didnt know what that does
i'll try this after configure ogre 1.6 and update the directx to june 2008
=]
almondega
29-08-2008 03:24:57
controller: accumulator works perfect
now i have smooth movements
tks for the help