( Yes, I am finally back, I had much to do, sorry community :D)
PhysX 3.3
Hello,
I want to move my PxBoxController when he hits a special sphere shape along a “path”.
The idea: Move the PxBoxController via the move(velocity,deltaTime,…) function, with
a precalculated velocity.
It should be simple calculated but the results must be determinstic and shouldn´t vary.
(The part of collision etc works perfect, the only problem is the mDeltaTime calculation of force.)
I know that my game is frame independent, and combining physics with apply forces to a kinematic object ( like the PxController) cant handle it right.
Appling forces to dynamic objects works perfect, all I need is to add the force.
But for kinematic objects (maybe espacially the PxController) cant handle it right, so I multipled
mDeltaTime for a much better result when the fps are changing, but all I get are different positions.
The goal is when I touch a special sphere ( from above) , I want to jump over it.
This must be deterministic, when its not, its possible to “cheat” because the player could jump
far or less away than it should.
(E.g. when he change windows or when he had a slow computer :D)
I dont know how to explain it better, but maybe this pic could help you:
Here are the “important” code snippets:
// Delta time calculation
unsigned long timeNow = mTimer->getMicroseconds();
mTimeSinceLastFrame = timeNow - mLastUpdateMs;
mLastUpdateMs = timeNow;
mDeltaTime = mTimeSinceLastFrame*0.001f;
// This is the calculation of the jump for the PxBoxController, it has a smooth curve
float jumpGravity = -2;
float jumpForce = 40.f;
mJumpTime += mDeltaTime*10;
mVelocity.y = (jumpGravity*mJumpTime*mJumpTime + jumpForce);
Vector3 dir = ... //Facing direction of my mesh, works
mVelocity.x = dir.x;
mVelocity.z = dir.z;
mVelocity *= mDeltaTime; //Same delta time which is used for physic update , here are the bug
.
.
.
mController->move(mVelocity,0.01f,mDeltaTime,PxControllerFilters());
// Now the physic update, semi-fixed-style:
mStepSize = 0.01f;
mAccumulator += mDeltaTime;
if (mAccumulator > 0.05f) mAccumulator = 0.05f;
while (mAccumulator >= mStepSize)
{
mAccumulator -= mStepSize;
mScene->simulate(mStepSize);
mScene->fetchResults(true,&errorCode);
}
Again: The problem is that the player is “jumping” always to a new position, and not to a
position which is always the same, mostly the changes are 0 - 1 units (in global position) or
when the delta time is very very very high, he could jump more than 10+ units away from the desired
position. (I cant tell what the desired position is, - its calculated thru the gravity and jump force,- but this should alway be the same result.)
E.g: The PxController should move 20 units in his “face” direction, but he also moves up (jump) and falls down ( gravity) .
I also tried adding force for a little while (frame independent!) but this also leads to vary results.
My question is: How could I archieve my jumping movement which is always at changing frames deterministic and gives me the right result?!
I guess one way is to call from the “hidden” PxActor inside PxController the
setKinematicTarget(…) for position the PxController, but this shouldnt be the right way,
we lost information like the possible collisionFlags while he is moving. ( See PxController::move())
I want to get any collision information which could happen while
the PxController is “jumping over” it, and I dont want to use a separate movement update for it.
But maybe this could be a solution to the problem, but again, I dont want to use it unless
there is a efficent and easy way via the “force” calculation.