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))));
}
}