[Unity] 정지 개체 뒤에 궤적 확장하기

6812 단어 Unity
자신의 기계가 항상 원점에 있으면 무엇이든 편리하다는 이유 때문에 실제로 스스로 멈추고 주변 사람들이 움직이는 방법도 있다.

이럴 때는'움직이는 느낌'을 표현하기 위해 트레일 렌더가 스스로 움직이지 않으면 트레일이 생기지 않는다.
따라서 Line Renderer를 사용하여 자신의 뒤에 경로를 만듭니다.
먼저 궤적의 시작점으로 빈 객체를 준비합니다.
링크를 연결합니다.

다음 스크립트를 같은 대상에 부속합니다
InvTrail.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InvTrail : MonoBehaviour {
    [SerializeField] float m_spd=10f;
    [SerializeField] int m_positionCount = 50;
    LineRenderer m_lr;
    Vector3[] m_oldPos;
    int m_cnt;

    // Use this for initialization
    void Start () {
        m_lr = GetComponent<LineRenderer>();
        if (!m_lr)
            Destroy(this);

        m_lr.positionCount = m_positionCount;
        m_oldPos = new Vector3[m_lr.positionCount];
        for (int i = 0; i < m_oldPos.Length; ++i)
        {
            m_oldPos[i] = transform.position;
        }
        m_lr.SetPositions(m_oldPos);
        m_cnt = m_oldPos.Length - 1;
    }

    // Update is called once per frame
    void Update () {
        Vector3 wSpd = transform.rotation * Vector3.back * m_spd;
        m_cnt = Mathf.Max(0,m_cnt - 1);
        for (int i = m_oldPos.Length-1; i > m_cnt; --i)
        {
            m_oldPos[i] = m_oldPos[i-1]+wSpd*Time.deltaTime;
        }
        m_oldPos[m_cnt] = transform.position;
        m_lr.SetPositions(m_oldPos);
    }
}
객체 뒤에 궤적 그리기

재료 및 모양새 이동 속도 등 매개변수 조정
m_spd는 외관의 속도, mpositionCount는 궤적의 정점 수입니다.

좋은 웹페이지 즐겨찾기