Skip to content

Commit 1a579ba

Browse files
committed
Basic melee VR attacks working
1 parent b047004 commit 1a579ba

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

Code/Melee.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Copyright (C), Crytek Studios, 2001-2006.
2424

2525

2626
#include "IRenderer.h"
27-
#include "IRenderAuxGeom.h"
27+
#include "IRenderAuxGeom.h"
28+
#include "VR/OpenXRRuntime.h"
29+
#include "VR/VRManager.h"
2830

2931

3032
//std::vector<Vec3> g_points;
@@ -106,16 +108,37 @@ void CMelee::Update(float frameTime, uint frameId)
106108
}
107109
}
108110

109-
SMovementState info;
110-
pMC->GetMovementState(info);
111-
pos = info.eyePosition;
112-
dir = info.eyeDirection;
113-
if (!PerformRayTest(pos, dir, strength, false))
114-
if(!PerformCylinderTest(pos, dir, strength, false))
115-
ApplyCameraShake(false);
116-
117-
m_ignoredEntity = 0;
118-
m_meleeScale = 1.0f;
111+
if (pActor->IsClient())
112+
{
113+
for (int i = 0; i < 2; ++i)
114+
{
115+
Vec3 velocity = gVR->GetControllerWorldVelocity(i);
116+
if (velocity.GetLength() < 1.5f)
117+
continue;
118+
119+
pos = gVR->GetWorldControllerTransform(i).GetTranslation();
120+
dir = velocity.GetNormalized();
121+
pos -= dir * 0.15f; // bit more wiggle room for hits
122+
if (PerformRayTest(pos, dir, strength, false) || PerformCylinderTest(pos, dir, strength, false))
123+
{
124+
gXR->GetInput()->SendHapticEvent(i == 0 ? LEFT_HAND : RIGHT_HAND, 0.15f, 0.6f);
125+
break;
126+
}
127+
}
128+
}
129+
else
130+
{
131+
SMovementState info;
132+
pMC->GetMovementState(info);
133+
pos = info.eyePosition;
134+
dir = info.eyeDirection;
135+
if (!PerformRayTest(pos, dir, strength, false))
136+
if(!PerformCylinderTest(pos, dir, strength, false))
137+
ApplyCameraShake(false);
138+
139+
m_ignoredEntity = 0;
140+
m_meleeScale = 1.0f;
141+
}
119142

120143
m_pWeapon->RequestMeleeAttack(m_pWeapon->GetMeleeFireMode()==this, pos, dir, m_pWeapon->GetShootSeqN());
121144
}

Code/NanoSuit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,9 @@ void CNanoSuit::PlaySound(ENanoSound sound, float param, bool stopSound)
11021102
case STRENGTH_MELEE_SOUND:
11031103
soundName = "Sounds/interface:suit:suit_strength_punch";
11041104
eSemantic = eSoundSemantic_NanoSuit;
1105-
if(m_pOwner->IsClient())
1105+
//if(m_pOwner->IsClient())
11061106
//if (gEnv->pInput && !stopSound) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.05f, 1.0f*param, 0.5f*param) );
1107-
if (!stopSound) gXR->GetInput()->SendHapticEvent(0.05f, 1.0f * param);
1107+
//if (!stopSound) gXR->GetInput()->SendHapticEvent(0.05f, 1.0f * param);
11081108
setParam = true;
11091109
break;
11101110
case ARMOR_SOUND:

Code/Player.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5421,7 +5421,7 @@ void CPlayer::PlaySound(EPlayerSounds sound, bool play, bool param /*= false*/,
54215421
soundName = "Sounds/physics:player_foley:melee_feedback";
54225422
soundSemantic = eSoundSemantic_Player_Foley_Voice;
54235423
//if (gEnv->pInput && play) gEnv->pInput->ForceFeedbackEvent( SFFOutputEvent(eDI_XI, eFF_Rumble_Basic, 0.15f, 0.6f, 0.2f) );
5424-
if (play) gXR->GetInput()->SendHapticEvent(0.15f, 0.6f);
5424+
//if (play) gXR->GetInput()->SendHapticEvent(0.15f, 0.6f);
54255425
break;
54265426
case ESound_Fear:
54275427
soundName = "Sounds/physics:player_foley:alien_feedback";

Code/VR/OpenXRInput.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,8 @@ void OpenXRInput::UpdateMeleeAttacks()
515515
for (int i = 0; i < 2; ++i)
516516
{
517517
Vec3 controllerVelocity = GetControllerVelocity(i);
518-
if (controllerVelocity.GetLength() > 2.f && controllerVelocity.Dot(hmdForward) > 0.f)
518+
if (controllerVelocity.GetLength() > 1.5f && controllerVelocity.Dot(hmdForward) > 0.f)
519519
{
520-
CryLogAlways("Potential melee attack triggered");
521520
weapon->MeleeAttack();
522521
break;
523522
}

0 commit comments

Comments
 (0)