Answer the question
In order to leave comments, you need to log in
Why does Vector3.MoveTowards move inaccurately?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
public float speed;
private Vector3 target;
public float xOffest;
private void Start()
{
target = transform.position;
}
private void FixedUpdate()
{
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Z))
{
target = new Vector3(transform.position.x + xOffest, transform.position.y, transform.position.z);
}
else if (Input.GetKeyDown(KeyCode.X))
{
target = new Vector3(transform.position.x - xOffest, transform.position.y, transform.position.z);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question