using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestPlayer : MonoBehaviour
{
[SerializeField]
private Transform sight;
private Quaternion rot;
private Vector3 targetTrans;
public float damping = 10f;
public void Move()
{
Ray ray = new Ray(this.sight.position, this.transform.forward);
Debug.DrawRay(ray.origin, ray.direction * 100f, Color.yellow, 5f);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100f))
{
DrawArrow.ForDebug(hit.point, hit.normal, 5f, Color.green, ArrowType.Solid);
Debug.Log(hit.normal);
rot = Quaternion.LookRotation(hit.normal);
this.targetTrans = Vector3.forward * hit.point.z + Vector3.right * hit.point.x;
this.transform.LookAt(this.targetTrans);
StartCoroutine(Comove(hit.normal));
}
}
private IEnumerator Comove(Vector3 vector)
{
while (true)
{
float dis = Vector3.Distance(this.transform.position, this.targetTrans);
if (dis < 0.2f)
break;
this.transform.Translate(Vector3.forward * Time.deltaTime);
yield return null;
}
while (true)
{
if (this.transform.forward == vector)
break;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, rot, Time.deltaTime * damping);
Debug.Log(this.transform.rotation);
yield return null;
}
}
}
'K-digital traning > 유니티 심화' 카테고리의 다른 글
[주말과제]UGUI+데이터 연동(1) (0) | 2023.09.10 |
---|---|
HeroShooter에 new Input System 적용 (0) | 2023.09.03 |
[주말과제] HeroShooter stage1까지 (0) | 2023.08.28 |
OverlapSphere 연습 (0) | 2023.08.21 |
[주말과제] 궁수의 전설 (0) | 2023.08.21 |