using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuaternionPlayerController : MonoBehaviour
{
[SerializeField]
private float moveSpeed = 1f;
private Quaternion rot;
// Start is called before the first frame update
void Start()
{
Ray ray = new Ray(this.transform.position, this.transform.forward);
RaycastHit hit;
DrawArrow.ForDebug(ray.origin, ray.direction * 100f, 5f, Color.green, ArrowType.Solid);
if(Physics.Raycast(ray, out hit, 100f))
{
this.rot = Quaternion.LookRotation(hit.normal);
}
}
// Update is called once per frame
void Update()
{
this.transform.Translate(Vector3.forward * this.moveSpeed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Wall")
{
this.moveSpeed = 0f;
this.transform.rotation = this.rot;
}
}
}
Ray ray는 마우스만 아니라 transform으로도 사용이 가능하다.
'유니티 심화' 카테고리의 다른 글
Reflect (0) | 2023.08.21 |
---|---|
절대강좌 유니티 - 깡통 주변 폭파, 3대 맞으면 파괴, 이펙트, (0) | 2023.08.21 |
절대강좌 유니티 - 총알 이펙트효과 (0) | 2023.08.21 |
[주말과제] - 궁수의 전설[완] (0) | 2023.08.19 |
SpaceShooter2D - 스페이스바 눌러서 총쏘고 제거하기 [완] (0) | 2023.08.18 |