I’m trying to make a script that make a block move in steps around another block on key down and it mostly seems to work only the movetowards and lerp don’t seem to move the block smoothly towards the destination point. How can I fix that?
using UnityEngine;
using System.Collections;
public class Move : MonoBehaviour {
public GameObject target = null;
public GameObject emptyGameObjectPrefab;
private float distance;
// Update is called once per frame
void Update () {
distance = Vector3.Distance (target.transform.position, transform.position);
move();
}
void move (){
if (Input.GetKeyDown(KeyCode.UpArrow))
{
GameObject Mover;
Mover = Instantiate(emptyGameObjectPrefab, transform.position,Quaternion.identity) as GameObject;
Mover.transform.RotateAround (target.transform.position, Vector3.up, 45/distance);
StartCoroutine(moveTo(Mover.transform.position));
}
}
IEnumerator moveTo(Vector3 pos) {
//transform.position = Vector3.Lerp(transform.position, pos, 1);
transform.position = Vector3.MoveTowards (transform.position, pos , 1);
transform.LookAt(target.transform.position);
yield return null;
}
}