Unity插值运算

发布时间:2024年01月18日
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson10 : MonoBehaviour
{

    public Transform targetObj;
    public float moveSpeed;
    private Vector3 targetPos;
    private Vector3 startPos;
    
    public float time;


    // Update is called once per frame
    void LateUpdate()
    {
        if(targetPos != targetObj.position + -targetObj.forward * 4 + targetObj.up * 7)
        {
            targetPos = targetObj.position + -targetObj.forward * 4 + targetObj.up * 7;
            startPos = this.transform.position;
            time = 0;
        }
        //先块后慢
        //this.transform.position = Vector3.Lerp(this.transform.position, targetPos, Time.deltaTime*moveSpeed);
        //this.transform.LookAt(targetObj);

        //匀速
        this.transform.position = Vector3.Lerp(startPos, targetPos, time * moveSpeed);
        time += Time.deltaTime;
        this.transform.LookAt(targetObj);
    }
}

文章来源:https://blog.csdn.net/lqd201314/article/details/135679334
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。