Aim fixed for all weapons

This commit is contained in:
viktorljung
2016-03-12 02:39:06 +01:00
parent 2a209c5d8e
commit 060585a388
9 changed files with 268 additions and 138 deletions
+25 -8
View File
@@ -82,17 +82,15 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// Limit camera pitch so we don't break our necks
cameraOrientation.x = glm::clamp(cameraOrientation.x, -glm::half_pi<float>(), glm::half_pi<float>());
float pitch = cameraOrientation.x;
double time = ((pitch + glm::half_pi<float>()) / glm::pi<float>());
// Set third person model aim pitch
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
if (playerModel.Valid()) {
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("Aim");
if(aimPrimaryEntity.Valid()){
if(aimPrimaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x;
double time = ((pitch + glm::half_pi<float>()) / glm::pi<float>());
(double&)aimPrimaryEntity["Animation"]["Time"] = time;
}
}
setAim(playerModel, "SidearmWeapon", time);
setAim(playerModel, "AssaultWeapon", time);
setAim(playerModel, "DefenderWeapon", time);
}
}
@@ -308,6 +306,25 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt)
position += velocity * (float)dt;
}
void PlayerMovementSystem::setAim(EntityWrapper root, std::string weaponNodeName, double time)
{
if (root.Valid()) {
EntityWrapper blendTreeUpper = root.FirstChildByName("BlendTreeUpper");
if (blendTreeUpper.Valid()) {
EntityWrapper weapon = blendTreeUpper.FirstChildByName(weaponNodeName);
if(weapon.Valid()) {
EntityWrapper aim = weapon.FirstChildByName("Aim");
if (aim.Valid()) {
if (aim.HasComponent("Animation")) {
(double&)aim["Animation"]["Time"] = time;
}
}
}
}
}
}
void PlayerMovementSystem::playerStep(double dt)
{
if (!m_LocalPlayer.Valid()) {