btKinematicCharacter Diagonal Movement

Post Reply
Random#9001
Posts: 10
Joined: Mon Mar 16, 2015 12:59 pm

btKinematicCharacter Diagonal Movement

Post by Random#9001 »

Here is a question I cant seem to find the answer too yet, how do I incorporate diagonal movement into my kinematic character?

My current code sets a target velocity and uses the vector3's interpolation to reach it. However I set it and that means only one command will get through making it only up, back, left or right. Do I just have to make extra commands for diagonals and test for w and a for example? or is there some math I can utilize to make the character move diagonally? Ive had trouble with this in the past, and any help would be appreciated.

Code: Select all

void PlayerObject::addToSpeedForward(float yaw, float speed) {
	if (character->onGround()){
		goalVelocity->setX(-(speed * sin(toRadians(yaw))));
		goalVelocity->setZ((speed * cos(toRadians(yaw))));
	}
}

void PlayerObject::addToSpeedBackWards(float yaw, float speed) {
	if (character->onGround()){
		goalVelocity->setX((speed * sin(toRadians(yaw))));
		goalVelocity->setZ(-(speed * cos(toRadians(yaw))));
	}
}
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btKinematicCharacter Diagonal Movement

Post by drleviathan »

The KinematicCharacter just takes a velocity, which means that if you supply a diagonal velocity then the controller will go that way. The solution lies in changing your own code that captures the "commands".

BTW I notice that your functions are incorrectly named. PlayerObject::addToSpeedForward(yaw, speed) doesn't actually add velocity -- it slams the X and Z components.
Post Reply