//============================================================================== // キャラクターと岩の押し戻し //============================================================================== void CGame::PushBackRock(void) { // 攻撃側の決定 CPlayer* pPlayer = nullptr; // 攻撃側プレイヤー for (int cntPlayer = 0; cntPlayer < PLAYER_MAX; ++cntPlayer) { // プレイヤーを取得 pPlayer = Player[cntPlayer]; // プレイヤーが判定可能か確認 if (NeedsSkipPlayer(pPlayer)) { continue; } // 防御側の決定 for (int cntRock = 0; cntRock < MAX_ROCK; ++cntRock) { // 岩を取得 CObject* pRock = ppRock_[cntRock]; // 岩オブジェクト // 当たり判定 VECTOR3 positionPlayer = pPlayer->Pos(); // 攻撃判定中心座標 VECTOR3 positionRock = pRock->Pos(); // 防御判定中心座標 VECTOR3 vectorOffenseToDefense; // 攻撃判定から防御判定へのベクトル float distanceOffenseAndDefense; // 判定の中心同士の距離 float scalingRock; // 岩の大きさ scalingRock = (pRock->Scl().x < pRock->Scl().z ? pRock->Scl().x : pRock->Scl().z); positionPlayer.y += HEIGHT_PUSH_CHARACTER; positionRock.y += HEIGHT_PUSH_ROCK; vectorOffenseToDefense = positionRock - positionPlayer; distanceOffenseAndDefense = sqrtf(vectorOffenseToDefense.x * vectorOffenseToDefense.x + vectorOffenseToDefense.y * vectorOffenseToDefense.y + vectorOffenseToDefense.z * vectorOffenseToDefense.z); if (distanceOffenseAndDefense < RADIUS_PUSH_CHARACTER + RADIUS_PUSH_ROCK * scalingRock) { // 押し戻し if (distanceOffenseAndDefense < -FLT_EPSILON || distanceOffenseAndDefense > FLT_EPSILON) { VECTOR3 vectorPushBack = vectorOffenseToDefense * -(RADIUS_PUSH_CHARACTER + RADIUS_PUSH_ROCK * scalingRock - distanceOffenseAndDefense) / distanceOffenseAndDefense; vectorPushBack.y = 0.0f; pPlayer->AddPos(vectorPushBack); pPlayer->AddDestPos(vectorPushBack); } else { pPlayer->AddPosX(RADIUS_PUSH_CHARACTER + RADIUS_PUSH_ROCK * scalingRock); pPlayer->AddDestPosX(RADIUS_PUSH_CHARACTER + RADIUS_PUSH_ROCK * scalingRock); } // エフェクト:火花 プレイヤーと岩のぶつかり } } } }
//============================================================================== // キャラクター同士の押し戻し //============================================================================== void CGame::PushBackCharacter(void) { // 攻撃側の決定 CPlayer* pPlayerOffense = nullptr; // 攻撃側プレイヤー for (int cntBullet = 0; cntBullet < PLAYER_MAX; ++cntBullet) { // プレイヤーを取得 pPlayerOffense = Player[cntBullet]; // プレイヤーが判定可能か確認 if (NeedsSkipPlayer(pPlayerOffense)) { continue; } // 防御側の決定 for (int cntPlayer = 0; cntPlayer < PLAYER_MAX; ++cntPlayer) { // プレイヤーを取得 CPlayer* pPlayerDefense = Player[cntPlayer]; // 防御側プレイヤー // プレイヤーが判定可能か確認 if (NeedsSkipPlayer(pPlayerDefense)) { continue; } if (cntBullet == cntPlayer) { continue; } // 当たり判定 VECTOR3 positionOffense = pPlayerOffense->Pos(); // 攻撃判定中心座標 VECTOR3 positionDefense = pPlayerDefense->Pos(); // 防御判定中心座標 VECTOR3 vectorOffenseToDefense; // 攻撃判定から防御判定へのベクトル float distanceOffenseAndDefense; // 判定の中心同士の距離 positionOffense.y += HEIGHT_PUSH_CHARACTER; positionDefense.y += HEIGHT_PUSH_CHARACTER; vectorOffenseToDefense = positionDefense - positionOffense; distanceOffenseAndDefense = sqrtf(vectorOffenseToDefense.x * vectorOffenseToDefense.x + vectorOffenseToDefense.y * vectorOffenseToDefense.y + vectorOffenseToDefense.z * vectorOffenseToDefense.z); if (distanceOffenseAndDefense < 2.0f * RADIUS_PUSH_CHARACTER) { // 押し戻し if (distanceOffenseAndDefense < -FLT_EPSILON || distanceOffenseAndDefense > FLT_EPSILON) { VECTOR3 vectorPushBack = vectorOffenseToDefense * 0.51f * (2.0f * RADIUS_PUSH_CHARACTER - distanceOffenseAndDefense) / distanceOffenseAndDefense; pPlayerDefense->AddPos(vectorPushBack); pPlayerDefense->AddDestPos(vectorPushBack); vectorPushBack *= -1.0f; pPlayerOffense->AddPos(vectorPushBack); pPlayerOffense->AddDestPos(vectorPushBack); } else { pPlayerOffense->AddPosX(RADIUS_PUSH_CHARACTER); pPlayerOffense->AddDestPosX(RADIUS_PUSH_CHARACTER); pPlayerDefense->AddPosX(-RADIUS_PUSH_CHARACTER); pPlayerDefense->AddDestPosX(-RADIUS_PUSH_CHARACTER); } // エフェクト:火花 プレイヤー同士のぶつかり } } } }