TestBulletController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestBulletController : MonoBehaviour
{
private Vector3 rotVec;
private Quaternion rot;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Ray ray = new Ray(this.transform.position, this.transform.forward);
RaycastHit hit;
DrawArrow.ForDebug(ray.origin, ray.direction * 100f, 2f, Color.green, ArrowType.Solid);
if(Physics.Raycast(ray, out hit, 100f))
{
this.rotVec = Vector3.Reflect(-this.transform.forward, hit.normal);
Debug.LogFormat("ray.direction: {0}, hit.normal: {1}", ray.direction, hit.point);
DrawArrow.ForDebug(hit.collider.transform.position, ray.direction, 5f, Color.yellow, ArrowType.Solid);
}
this.transform.Translate(Vector3.forward * 3f * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Wall")
{
this.transform.rotation = Quaternion.LookRotation(-rotVec);
}
}
}
'유니티 심화' 카테고리의 다른 글
HeroShooter - 튜토리얼 스테이지 (0) | 2023.08.22 |
---|---|
OverlapSphere[수정필] (0) | 2023.08.21 |
절대강좌 유니티 - 깡통 주변 폭파, 3대 맞으면 파괴, 이펙트, (0) | 2023.08.21 |
절대강좌 유니티 - Quaternion.LookRotation (0) | 2023.08.21 |
절대강좌 유니티 - 총알 이펙트효과 (0) | 2023.08.21 |