I'm trying to design a spitball/poison type projectile that will travel until it reaches the point clicked on screen and then destroys itself. The problem is that contrary to what almost everyone says, Vector3.Movetowards is not moving the ball at a constant speed. If the target location is close to the launcher it moves slowly, if it is further away it moves much faster.
public float speed = 5f;
public Vector3 target = new Vector3();
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, target,speed * Time.deltaTime);
}
Adding the launcher script
private void Shooting()
{
if (Input.GetMouseButton(0))
{
if (Time.time >= shotTime)
{
GameObject poison = Instantiate(Projectile, shotPoint.position, transform.rotation);
Vector3 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = 10f;
poison.GetComponent<PoisonBall>().target = target;
shotTime = Time.time + timeBetweenShots;
}
}
}
Vector3.MoveTowards
moves the current position towards the target with whatever speed (or better maximum step size per call) you pass in, if it is constant linear and the target position doesn't change meanwhile then the movement will be so. The behavior you describe is not reproducible or missing additional information specific to your case – derHugo