Hey all, i know this is probably something very simple, but i have a game object that will just be an NPC, moving to 4 points on the 2d top down, and used something similar to:
howevever in my code below, I have an Vector 2 Array, that has 2 (total 3 if you count the zero), locations including home vector 2, and depending where or what vector the npc/game object is, move to the next one, however, it never leaves the home, I do have a debug on it, and it does show up in the console, however the 2d object never moves, it does have a box collider 2d on it, doesnt have a rigid body, which i tried, but still doesnt move… any ideas?
void MoveCharacter(float steps)
{
//Move X first, then move Y
Debug.Log("Moving!");
if(currentPosition == homePosition)
{
this.transform.position = Vector2.MoveTowards(transform.position, targetPosition[0], steps);
Debug.Log("Moving to first spot!");
}
if(currentPosition == targetPosition[0])
{
this.transform.position = Vector2.MoveTowards(transform.position, targetPosition[1], steps);
}
if (currentPosition == targetPosition[1])
{
this.transform.position = Vector2.MoveTowards(transform.position, targetPosition[2], steps);
}
else
{
this.transform.position = Vector2.MoveTowards(transform.position, homePosition, steps);
}
}
private void Update()
{
float moveSteps = moveSpeed * Time.deltaTime;
if (TimeToMoveCountdown >= 0.0f)
{
TimeToMoveCountdown -= Time.deltaTime;
}
else
{
MoveCharacter(moveSteps);
TimeToMoveCountdown = OGTimeToMoveCountdown;
}
}