1. 레이저 발사
레이저 발사 위치 빈오브젝트 생성
line renderer 로 간단한 레이저 만들기
처음에 큐브로 레이저를 막아도 레이저가 끊기지 않고 아래 사진처럼 계속 나가길래
로그를 찍어봤더니 else만 나오고 hit collider가 전혀 찍히지 않았다.
그래서 ray를 그려봤더니 엉뚱한 곳으로 나가고 있었다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Laser : MonoBehaviour
{
private LineRenderer lr;
[SerializeField] private Transform attackPos;
private void Start()
{
this.lr = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update()
{
lr.SetPosition(0, this.attackPos.position);
RaycastHit hit;
Debug.DrawRay(this.attackPos.position, this.attackPos.forward * -1000f, Color.blue);
if (Physics.Raycast(this.attackPos.position, this.attackPos.forward*-1000f, out hit))
{
if (hit.collider)
{
lr.SetPosition(1, hit.point);
Debug.Log("hit collider");
}
}
else
{
lr.SetPosition(1, attackPos.forward * -1f * 500);
Debug.Log("else");
}
}
}
수정한 모습
큐브를 방패로 변경
추가해야할 것 , 플레이어를 향해서 쏘기(플레이어가 이동하면 따라가기), 법선방향으로 튀기는 이펙트, 막으면 방패에 빛나는 이펙트
플레이어 향해서 쏘기
LookAt을 써서 centereyeanchor를 향하도록 했는데 둘 다 이상한곳으로 쏜다.. 드론은 심지어 반대로 쏨...?
그래서 centereyeanchor가 문제인가 해서 sphere를 만들어서 구에게 쏘도록 했는데 이것도 이상함
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundEnemy : MonoBehaviour
{
public Transform target;
public float offset;
// Update is called once per frame
void Update()
{
this.transform.LookAt(target, Vector3.up);
}
}
각도가 이상해서 그렇지 잘 바라보긴한다..
레이저 발사 방향을 바꾸니 잘 공쪽으로 레이저를 쏜다
공의 위치 대신에 center eye를 넣어보자
oculus로 실행
너무 눈으로 쏘는 느낌이 강하긴 하다. offset을 줘서 살짝 아래(몸통)쪽을 공격하도록 한다.
offset을 -0.3으로 주니 몸통으로 쏘는 느낌이다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GroundEnemy : MonoBehaviour
{
public Transform target;
[SerializeField]
private float targetOffset = -0.5f;
// Update is called once per frame
void Update()
{
var lookAtPos = this.target.position + (this.target.up * this.targetOffset);
this.transform.LookAt(lookAtPos);
}
}
지상 적이 오른쪽으로 쏘는거같은 느낌의 이유는 몸이 구를 바라보면 총구가 오른쪽으로 향하기 때문이다.
총구를 회전을 임의로 맞도록 회전할라했으나 캐릭터가 총구를 잡는 모양이 어색하다
=> 그래서 총에도 Lookat을 적용하였다.
제대로 플레이어를 향해 공격하는 모습!!!
'마블 VR 프로젝트 제작' 카테고리의 다른 글
[마블 VR] 공중적 레이저 발사/방패 막기 버그 수정 (0) | 2023.12.12 |
---|---|
[마블 VR] 공중적 레이저 발사/방패 막기(+방패 진동) 다듬기 (3) | 2023.12.08 |
[마블 VR] oculus를 사용해서 반경 안에 있는 적 공격하기 R&D (2) | 2023.12.03 |
[마블 VR] 오프젝트 풀링으로 공중 적 생성하기 R&D (0) | 2023.11.30 |
[마블 VR] 방패 던지기(적이 없는 경우) (0) | 2023.11.27 |