▶수정 목표
: 방패가 총알에 닿을 때 애니메이션 및 컨트롤러 진동 효과(햅틱반응) 주기
.
.
.
방패로 총알을 막을 때 연출이 다소 밋밋하다고 생각하여,
방패(Shield)에 Animation 및 총알과 충돌했을때 컨트롤러 진동 효과(햅틱반응)를 주도록 수정하였다!
▶ 총알에 닿으면 크기 커졌다 작아졌다하는 애니메이션 추가하기
-Shield 부분에 Shield Animator를 넣어주고

ShieldBullet Animation을 만들어 총알을 맞을 때 마다 원래 크기에서 조금 커졌다가 작아지게 만들었다.

기존 Shield 스크립트에 아래와 같이 코루틴 함수를 추가해 주었다.
using System.Collections;
using UnityEngine;
public class Shield : MonoBehaviour
{
public System.Action onTriggerBullet;
private Animator anim;
void Start()
{
this.anim = this.GetComponent<Animator>();
}
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Bullet"))
{
Debug.LogFormat("<color=blue>ShieldBullet: {0}</color>",other.name);
//애니메이션 실행
StartCoroutine(CoShieldAnim());
this.onTriggerBullet();
Destroy(other.gameObject);
}
}
//애니메이션 코루틴
private IEnumerator CoShieldAnim()
{
this.anim.SetBool("isShield", true);
Debug.Log("<color=green>AnimationDone</color>");
yield return new WaitForSeconds(0.15f);
this.anim.SetBool("isShield", false);
}
}
총알에 닿으면 커졌다가 작아졌다하는 애니메이션이 실행된다~!

▶ 총알에 닿으면 컨트롤러 진동 효과 주기
OVRInput.SetControllerVibration 함수를 사용해주었다.
OVRInput.SetControllerVibration ( float frequency, float amplitude, OVRInput.Controller controllerMask )
**frequency : (0~1) 진동의 주파수 값
**amplitude : (0~1) 진동의 진폭 값
**OVRInput.Controller : 진동을 설정할 컨트롤러
따라서 Shield 스크립트에 아래와 같이 추가해주었다!
총알을 맞을 때 마다 방패를 든 왼손 컨트롤러에 0.15초씩 진동이 느껴졌다.
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Bullet"))
{
Debug.LogFormat("<color=blue>ShieldBullet: {0}</color>",other.name);
StartCoroutine(CoShieldAnim());
//컨트롤러 진동 코루틴 실행
StartCoroutine(CoControllerVibe(0.1f,0.1f,OVRInput.Controller.LTouch));
this.onTriggerBullet();
Destroy(other.gameObject);
}
}
//컨트롤러 진동 코루틴
private IEnumerator CoControllerVibe(float frequency, float amplitude, OVRInput.Controller controllermask)
{
OVRInput.SetControllerVibration(frequency,amplitude,controllermask);
yield return new WaitForSeconds(0.15f);
OVRInput.SetControllerVibration(0, 0, controllermask);
}
▷ 참고한 블로그
Unity Oculus 컨트롤러 진동
https://developer.oculus.com/documentation/unity/unity-haptics/ static void OVRInput.SetControllerVibration ( float frequency, float amplitude, Controller controllerMask ) OVR Haptic 대신 OVR.Input 의 SetControllerVibration 함수를 사용해 컨트롤
rokka.tistory.com
▶실행 모습

'VR 팀프로젝트 > [GroundZero] 제작 일지' 카테고리의 다른 글
GroundZero 플레이 영상 및 소감 (0) | 2024.01.23 |
---|---|
GroundZero 제작일지 - GameOverScene 수정 및 GameClearScene (0) | 2024.01.12 |
GroundZero 제작일지 - 바주카포 총 수정 (0) | 2024.01.03 |
GroundZero 제작일지 - Lobby Scene 데이터 연동 및 연출 R&D (0) | 2023.12.27 |
GroundZero 제작일지 - GameOverScene 구현 (1) | 2023.12.21 |