Kinematic Character problems while moving

nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Kinematic Character problems while moving

Post by nickfla1 »

Hey guys!
Probably I can't explain in english what's happening so I just made THIS video showing the problem.
As you can see the character isn't moving properly(I think the correct word is 'flickering' but I don't know)
This 'thing' is accentuated by the fact that I'm recording but it happends also when I'm not

Ps: sorry if the video is a little bit dark

Edit: Here's the source code of the moving function

Code: Select all

void Move(float elapsedTime, bool f, bool b, bool l, bool r, bool j, Camera* cam){
		if(m_pCharacterController){
			btTransform xform;
			xform = m_pCharacterGhostObject->getWorldTransform();	

			btVector3 forwardDir = xform.getBasis()[2];			
			btVector3 upDir = xform.getBasis()[1];
			btVector3 strafeDir = xform.getBasis()[0];						

			forwardDir.normalize();
			upDir.normalize();
			strafeDir.normalize();

			btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
			btScalar walkVelocity = btScalar(1.1f) * 50.0f;
			btScalar walkSpeed = walkVelocity * elapsedTime;

			if (l)
				walkDirection -= strafeDir;

			if (r)
				walkDirection += strafeDir;

			if (f)
				walkDirection += forwardDir;

			if (b)
				walkDirection -= forwardDir;	

			m_pCharacterController->setWalkDirection(walkDirection * walkSpeed);	

			btMatrix3x3 basis;				
			forwardDir.setX((float)sin(cam->GetYaw()));
			forwardDir.setY(0.0f );
			forwardDir.setZ((float)cos(cam->GetYaw()));		

			strafeDir.setX((float)cos(cam->GetYaw()));
			strafeDir.setY(0.0f );
			strafeDir.setZ((float)-sin(cam->GetYaw()));

			upDir = xform.getBasis()[1];
			forwardDir.normalize();
			upDir.normalize();
			strafeDir.normalize();

			basis.setValue(strafeDir.x(), strafeDir.y(), strafeDir.z(),
				upDir.x(), upDir.y(), upDir.z(),
				forwardDir.x(), forwardDir.y(), forwardDir.z());

			xform.setBasis(basis);
			m_pCharacterController->getGhostObject()->setWorldTransform(xform);		
			cam->SetPosition(&Utility::ConvertVector(xform.getOrigin()));
		}
	}
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Kinematic Character problems while moving

Post by nickfla1 »

Up.
Come on, really no one knows how to solve this?
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Kinematic Character problems while moving

Post by STTrife »

It kinda looks like lag to me. I don't think the code you posted is directly responsible for the weird behaviour. Have you monitored the FPS? Does it go down during the flickering?
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Kinematic Character problems while moving

Post by nickfla1 »

Both FPS and elapsedTime are stable during the flickering.
I tried adding values to the position without using the function setWalkDirection and it perfectly works, well at least untill it doesn't collide with a wall or something then it massively flickers.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Kinematic Character problems while moving

Post by STTrife »

Well I never used the Character controller, but what I can see from the code is that in the function playerStep, it seems to already use the elapsed time to calculate movement. So my guess would be that setWalkDirection should be called with something independent of the elapsed time in that frame. Basically just a vector with the direction adjusted to the desired speed, but not corrected for frametime.
But it's a pretty wild guess.. i.e. change

Code: Select all

m_pCharacterController->setWalkDirection(walkDirection * walkSpeed);
to

Code: Select all

m_pCharacterController->setWalkDirection(walkDirection * walkVelocity );  
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Kinematic Character problems while moving

Post by nickfla1 »

Hey, sorry I thought I had replied. Anyway it seems to work.
Thanks :)