FPS controller - Change player speed in run time

FPS controller - Change player speed in run time

How can i change player speed in run-time?

I put this code inside of controller update since i want to change it in run time but didn't work:


After that i tried this:

input.m_velocity = m_pOgreHavokBody->getHavokBody()->getLinearVelocity();

With a range of values [2.0f..2.5f] i didn't notice any changes and with the range [2,5f..3.0f] or more it's too fast.

EDIT: it seems when i press forward + strafe right or left it raises velocity with the ranges [2.0f..2.5f], it seems that is adding velocity in the wrong axis(diagonal).

Ogre::Vector3 dir = cGraphicalInterface::getSingleton().getCamera()->getDirection();
input.m_forward.set( dir.x,dir.y,dir.z);

Any sugestions?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I found the solution, this is the state machine creation:

// Create the Character m_pState machine and context
		hkpCharacterStateManager* manager = new hkpCharacterStateManager();

		m_pStateGround = new hkpCharacterStateOnGround();
		manager->registerState( m_pStateGround,	HK_CHARACTER_ON_GROUND);

		m_pState = new hkpCharacterStateInAir();
		manager->registerState( m_pState,	HK_CHARACTER_IN_AIR);

		m_pState = new hkpCharacterStateJumping();
		manager->registerState( m_pState,	HK_CHARACTER_JUMPING);

		m_pState = new hkpCharacterStateClimbing();
		manager->registerState( m_pState,	HK_CHARACTER_CLIMBING);

		m_characterContext = new hkpCharacterContext( manager, HK_CHARACTER_ON_GROUND );

		// Set character type

As you can see i created a specific state for onGround event instead of using m_pState and remove his reference after.
I'm calling this specific state in character controller update:


I hope this help someone else.

Leave a Comment

Please sign in to add a comment. Not a member? Join today