- Home /
Does the speed of the object depends on target distance while using vector3.movetowards()
I am trying to make a Piano Tiles type game in unity. So I have 6 empty gameobjects(targetGrid[0-5]) which are the targets of my tiles. I am sending my first tiles to first target[0], after reaching targetGrid[0] I'm making the new target to targetGrid1 and so on.
But the problem is the speed of my tile is slower from targetGrid[0]-targetGrid1 than the others like:
speedOf targetGrid[1-2] = speedOf targetGrid[2-3] = speedOf targetGrid[3-4] = speedOf targetGrid[4-5] is greater than speedOftargetGrid[0-1]
Here is the video of the problem : https://www.youtube.com/watch?v=20pwdbaw0aQ
here is the project package :
Why is that ?? And how can i solve this problem.
Here is my code and screenShot: public List gridPos = new List ();
//public bool middleCrossed = false;
//public CollectableTypes collectableTypes;
public CollectibleManager collectableManager;
private int currentGridNo = 0;
// Use this for initialization
void Start () {
transform.position = new Vector3 (gridPos[0].position.x,gridPos[0].position.y);
}
// Update is called once per frame
void Update () {
if(currentGridNo<5)
transform.position = Vector3.MoveTowards (transform.position, gridPos [currentGridNo+1].position, collectableManager.collectable_speed*Time.deltaTime);
if (transform.position == gridPos [Mathf.Clamp((currentGridNo+1),0,5)].position) {
if (currentGridNo < 5) {
Debug.Log ("calling " + currentGridNo + " Grid");
MakeNextObjectGo ();
}
else {
Debug.Log ("calling ManagerFunction");
currentGridNo = 0;
transform.position = new Vector3 (gridPos[currentGridNo].position.x, gridPos[currentGridNo].position.y);
}
}
}
public void MakeNextObjectGo()
{
currentGridNo++;
collectableManager.WhichGridCrossedGridCrossed (transform);
}
public void StartAgain()
{
collectableManager.FinishedMoving (transform);
}
}
to answer your question, no, the speed does not depend on distance, except for the last step to reach the target position, because it won't overshoot.
you should log the calculated speed and watch it for one piece. I think it changes.