/** This function is called every frame. It returns true only when the current action requires an object to execute a script. Otherwise, it either moves the Actor via MoveToNextNode(), or updates the Actor's current action. */ bool Actor::DoCurAction() { switch(GetCurAction()) { // If there is no action, then we should not need to animate. case IS_NOACTION: SetAutoAnimate(false); return false; break; case IS_WALK: // If the actor has reached the action coordinates, then // set her current action to IS_NOACTION. if(AtCurActionCoord()) { SetFacingDirection(); SetCurAction(IS_NOACTION, NULL, 0, 0); return false; } // Otherwise, move her to the next node via the pathfinder. else { MoveToNextNode(); return false; } break; default: if(!AtCurActionCoord()) { MoveToNextNode(); return false; } // If another action is the current action and the actor is at // the action coordinates, then we must process an object script. // return true. else { SetFacingDirection(); return true; } } }
void Player::CalculateFacingAngle() { DirectX::XMFLOAT3 v1 = DirectX::XMFLOAT3(1.0f, 0.0f, 0.0f); DirectX::XMFLOAT3 v2 = GetAttackDirection(); float x = (v1.x * v2.z) - (v2.x * v1.z); float y = (v1.x * v2.x) - (v1.z * v2.z); float faceAngle = atan2(y, x) - 1.57079632679f; SetFacingDirection(DirectX::XMFLOAT3(GetFacingDirection().x, faceAngle, GetFacingDirection().z)); }