Lerp .. p.188
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LerpSlerpMain : MonoBehaviour
{
[SerializeField]
private Transform startTrans;
[SerializeField]
private Transform endTrans;
[SerializeField]
private Transform pointTrans;
[SerializeField]
[Range(0, 1)]
private float lerpValue;
// Update is called once per frame
void Update()
{
Vector3 pos = Vector3.Lerp(this.startTrans.position, this.endTrans.position, this.lerpValue);
this.pointTrans.position = pos;
if(this.pointTrans.position == this.startTrans.position)
{
this.pointTrans.LookAt(this.endTrans.position);
}
else if(this.pointTrans.position == this.endTrans.position)
{
this.pointTrans.LookAt(this.startTrans.position);
}
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(this.startTrans.position, this.endTrans.position);
}
}
경과시간
Slerp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LerpSlerpMain : MonoBehaviour
{
[SerializeField]
private Transform startTrans;
[SerializeField]
private Transform endTrans;
[SerializeField]
private Transform startTrans2;
[SerializeField]
private Transform endTrans2;
[SerializeField]
private Transform pointTrans;
[SerializeField]
private Transform pointTrans2;
[SerializeField]
[Range(0, 1)]
private float lerpValue;
[SerializeField]
[Range(0, 1)]
private float slerpValue;
// Update is called once per frame
void Update()
{
Debug.Log(Time.deltaTime * 10f);
//Vector3 pos = Vector3.Lerp(this.startTrans.position, this.endTrans.position, this.lerpValue);
//this.pointTrans.position = pos;
//Vector3 pos2 = Vector3.Slerp(this.pointTrans2.position, this.endTrans.position, this.slerpValue);
//this.pointTrans2.position = pos2;
this.pointTrans.position = Vector3.Lerp(this.pointTrans.position, this.endTrans.position, Time.deltaTime * 1f);
this.startTrans.position = this.pointTrans.position;
this.pointTrans2.position = Vector3.Slerp(this.pointTrans2.position, this.endTrans2.position, Time.deltaTime * 1f);
this.startTrans2.position = this.pointTrans2.position;
if(this.pointTrans.position == this.startTrans.position)
{
this.pointTrans.LookAt(this.endTrans.position);
}
else if(this.pointTrans.position == this.endTrans.position)
{
this.pointTrans.LookAt(this.startTrans.position);
}
if (this.pointTrans2.position == this.startTrans2.position)
{
this.pointTrans2.LookAt(this.endTrans2.position);
}
else if (this.pointTrans2.position == this.endTrans.position)
{
this.pointTrans2.LookAt(this.startTrans2.position);
}
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(this.startTrans.position, this.endTrans.position);
Gizmos.DrawLine(this.startTrans2.position, this.endTrans2.position);
}
}
'유니티 심화' 카테고리의 다른 글
챕터5 - 총알 (0) | 2023.08.18 |
---|---|
Ref (0) | 2023.08.18 |
캐릭터 애니메이션 추가 (0) | 2023.08.18 |
절대강좌 유니티 - 카메라 distance, height 이동 (0) | 2023.08.18 |
Vector3.normalized (0) | 2023.08.18 |