TIL

2024/01/18 TIL

미역제자 2024. 1. 18. 21:08


 

Trouble Shooting

발판을 되감기 할때 발생하는 문제 해결

 

오류 코드
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FloatingPath : MonoBehaviour
{
    public Ease ease;

    public Transform waypoint1;
    public Transform waypoint2;
    public Transform waypoint3;

    private Vector3[] wayPoints;

    private void Start()
    {
        DOTween.Init(false, true, LogBehaviour.ErrorsOnly);

        wayPoints = new Vector3[4];
        wayPoints.SetValue(waypoint1.position, 0);
        wayPoints.SetValue(waypoint2.position, 1);
        wayPoints.SetValue(waypoint3.position, 2);
        wayPoints.SetValue(transform.position, 3);

        transform.DOPath(wayPoints, 6.0f, PathType.Linear).SetEase(ease).SetLoops(-1, LoopType.Restart).SetUpdate(UpdateType.Fixed, false) ;

    }
}

 

문제점

움직이는 발판에 일반적인 되감기를 사용하면 DOPath로 인해서 순간이동하는 현상이 생긴다.
->DOPath와 되감기의 position차이로 인한 충돌로 예상.

 

해결시도
  • 되감기 중 DOPath를 비활성화 하는 방법
    • 되감기 중 Dotween을 비활성화 한 후에 다시 활성화를 시키면 물체의 경로가 꼬이는 문제가 발생.
    • Path를 사용하기 위해 waypoint를 지정해 주는데, 물체의 처음 시작점을 waypoint 0번으로 잡아서 경로가 틀어진다고 판단했다.
해결한 방법
  • Dotween으로 되감기를 따로 구현하는 방법.
    • Dotween으로 움직이는 물체는 Record 스크립트를 넣지 말고 Dotween을 역재생 하는 방식으로 구현하는게 더 간편하고 자연스러울 것이라 생각했다.
    • 되감기 중에는 DOTween.DoPlayBackwards()를 통해 경로를 따라 되돌리고, 되감기가 끝나면 다시 DOTween.PlayForwards()를 사용해 다시 경로대로 이동하도록 만들었다.

 

 

 

'TIL' 카테고리의 다른 글

2024/01/22 TIL  (0) 2024.01.22
2024/01/19 TIL  (0) 2024.01.19
2024/01/17 TIL (움직이는 발판 구현)  (0) 2024.01.17
2024/01/16 TIL (Character Controller TroubleShooting)  (0) 2024.01.17
2024/01/15 TIL  (0) 2024.01.15