Different ways to move in unity3d Part2 | MoveTowards and lerp in unity

Subscribers:
1,030
Published on ● Video Link: https://www.youtube.com/watch?v=gSf2CQgc5Ug



Duration: 2:17
66 views
5


Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectMover : MonoBehaviour
{
public Vector3 speed;
public Transform target;
public float stepSpeed;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
float verticalInput = Input.GetAxis("Vertical");



//float step = stepSpeed * Time.deltaTime;

//transform.position = Vector3.MoveTowards(transform.position,target.position,step*verticalInput);


transform.position = Vector3.Lerp(transform.position,transform.position+(speed*Time.deltaTime*verticalInput),1f);



}
}