▣ 카메라 쉐이크(Camera Shake) 기능
설명: 총을 발사할 때 카메라가 일시적으로 흔들리면서 강렬한 반동 효과를 제공하는 기능입니다.
카메라의 월드 좌표계를 기준으로 카메라를 무작위로 흔들고, 흔들림이 끝난 후 원래 위치로 복구하는 방식입니다.
동작: 카메라의 원래 위치를 저장하고, 무작위로 X, Y 축 방향에 작은 오프셋을 더해 흔들린 효과를 줍니다. 시간이 지나면 카메라를 원래 위치로 복구합니다.
코드 구조:
StartCameraShake(): 카메라 쉐이크를 시작하는 함수로,
기존 쉐이크 코루틴이 진행 중이면 중지하고 새로운 코루틴을 시작합니다.
CameraShake(float duration, float magnitude): 일정 시간 동안 카메라에 무작위 흔들림을 적용하는 코루틴입니다.
▣ 반동(Recoil) 기능
설명: 총을 발사할 때 카메라가 위로 살짝 올라가는 반동 효과를 구현한 기능입니다. 발사할 때 반동 각도를 증가시키고, 시간이 지나면서 점진적으로 감소시켜 자연스러운 반동 복구 효과를 제공합니다.
동작: 카메라의 회전을 월드 좌표계를 기준으로 처리하여, 카메라의 기존 회전값에 반동 각도를 추가합니다. 시간이 지나면서 반동을 서서히 감소시키는 로직을 적용합니다.
코드 구조:
ApplyRecoil(): 카메라에 반동을 적용하는 함수로, 발사할 때 X축 방향으로 카메라가 위로 올라가는 반동을 적용합니다.
Update()에서는 currentRecoil 값을 점진적으로 감소시키며, 카메라가 서서히 원래 상태로 복구되도록 처리합니다.
▣ 무기 발사(Raycast) 기능
설명: 총기 모드에 따라 Raycast를 발사하여 타겟을 맞추는 기능입니다. 권총 모드에서는 단일 Raycast, 샷건 모드에서는 여러 개의 Raycast가 퍼져 나가며 타겟을 감지합니다.
동작: 카메라의 중심에서 Raycast를 발사하여 충돌한 오브젝트의 정보를 출력합니다. 샷건 모드에서는 여러 방향으로 퍼지는 Raycast를 통해 샷건 발사 효과를 제공합니다.
코드 구조:
FirePistol(): 권총 모드에서 단일 Raycast를 발사합니다.
FireShotgun(): 샷건 모드에서 여러 개의 Raycast를 퍼뜨려 발사합니다.
▣ 샷건 퍼짐(Spread) 기능
설명: 샷건 발사 시 여러 개의 총알이 퍼져 나가는 효과를 구현한 기능입니다. 각 Raycast가 무작위로 퍼지도록 각도를 계산하여 다양한 방향으로 발사됩니다.
동작: X, Y 축을 기준으로 무작위 각도를 생성한 후, 해당 각도로 Raycast 방향을 변경하여 퍼짐 효과를 구현합니다.
코드 구조:
GetSpreadDirection(): 샷건 발사 시 퍼짐 각도를 무작위로 계산해 새로운 방향을 반환하는 함수입니다.
https://docs.unity3d.com/ScriptReference/Camera-main.html
Unity - Scripting API: Camera.main
If there is no enabled Camera component with the "MainCamera" tag, this property is null. Internally, Unity caches all GameObjects with the "MainCamera" tag. When you access this property, Unity returns the first valid result from its cache. Accessing this
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Unity - Scripting API: Physics.Raycast
Description Casts a ray, from point origin, in direction direction, of length maxDistance, against all colliders in the Scene. You may optionally provide a LayerMask, to filter out any Colliders you aren't interested in generating collisions with. Specifyi
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/Quaternion.Euler.html
Unity - Scripting API: Quaternion.Euler
Description Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis; applied in that order. Description Returns a rotation that rotates z degrees around the z axis, x degrees around the x ax
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html
Unity - Scripting API: Debug.DrawRay
The duration parameter determines how long the line will be visible after the frame it is drawn. If duration is 0 (the default) then the line is rendered 1 frame. If depthTest is set to true then the line will be obscured by other objects in the Scene that
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/Coroutine.html
Unity - Scripting API: Coroutine
Coroutine class in UnityEngine / Inherits from:YieldInstruction / Implemented in:UnityEngine.CoreModule Description MonoBehaviour.StartCoroutine returns a Coroutine. Instances of this class are only used to reference these coroutines, and do not hold any e
docs.unity3d.com
https://assetstore.unity.com/packages/3d/characters/survivalist-character-181470
Survivalist character | 3D 캐릭터 | Unity Asset Store
Elevate your workflow with the Survivalist character asset from Slayver. Find this & other 캐릭터 options on the Unity Asset Store.
assetstore.unity.com
'[ Unity ] > - 유니티 실습' 카테고리의 다른 글
유니티 Material Tiling (4) | 2024.10.10 |
---|---|
유니티 AI 상태 코드 (0) | 2024.10.04 |
유니티 3D 아이템 감지(BoxCast) (3) | 2024.10.02 |
유니티 Build Setting (7) | 2024.10.02 |
유니티 Avatar Make 활용 조준, 발사 애니 재생 (14) | 2024.10.01 |
댓글