Move Object to Destination Smoothly Unity3D

前端 未结 2 1090
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 18:06

I am trying the whole day to move an object from point A to point B smoothly, so I tried Lerp, MoveTowards

2条回答
  •  臣服心动
    2021-01-16 18:49

    Try this:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class SmoothMove : MonoBehaviour 
    {
        public float speed = 0.01f;
        private Vector3 destination;
    
        void Start()
        {
            destination = transform.position;
        }
    
        void Update()
        {
            transform.position = Vector3.Lerp(transform.position, destination, speed)
        }
    
        void SetDestination(Vector3 newPos)
        {
            destination = newPos;
        }
    }
    

    I hope it helps you.

提交回复
热议问题