Hello,
sorry hope this is in the right location,
so I have my NPC finally working, its able to go to 4 points on the map, with the code below:
internal Transform thisTransform;
// The movement speed of the object
public float moveSpeed = 2.0f;
// A minimum and maximum time delay for taking a decision, choosing a direction to move in
public Vector2 decisionTime = new Vector2(10, 14);
public float TimeCountdown = 5;
private float defaultTimeCountdown;
private int currentMoveDirection;
public Transform[] targetSpots;
//public Animator NpcAnimator;
//public Rigidbody2D rgb;
public void MoveAnimation()
{
/*
if (speed <= 0.1)
{
NpcAnimator.SetFloat("Speed", 0);
}
else
{
NpcAnimator.SetFloat("Horizontal", dirx);
NpcAnimator.SetFloat("Vertical", diry);
NpcAnimator.SetFloat("Speed", speed);
}
*/
/*
if (angle <= 145 && angle >= 35)
{
//catAnimator.SetFloat("LastHorizontal", 0f);
//catAnimator.SetFloat("LastVertical", 1f);
}
else if (angle <= 34 && angle >= -34)
{
//catAnimator.SetFloat("LastHorizontal", 1f);
//catAnimator.SetFloat("LastVertical", 0f);
}
else if (angle <= -34 && angle >= -145)
{
//catAnimator.SetFloat("LastHorizontal", 0f);
//catAnimator.SetFloat("LastVertical", -1f);
}
else
{
//catAnimator.SetFloat("LastHorizontal", -1f);
//catAnimator.SetFloat("LastVertical", 0f);
}*/
}
void Start()
{
defaultTimeCountdown = TimeCountdown;
thisTransform = this.transform;
currentMoveDirection = 0;
}
// Update is called once per frame
void Update()
{
MoveAnimation();
if (TimeCountdown > 0)
{
TimeCountdown -= Time.deltaTime;
}
else
{
if (currentMoveDirection < (targetSpots.Length - 1))
{
currentMoveDirection++;
TimeCountdown = defaultTimeCountdown;
}
else
{
currentMoveDirection = 0;
TimeCountdown = defaultTimeCountdown;
}
}
if (currentMoveDirection <= (targetSpots.Length - 1))
{
transform.position = Vector2.MoveTowards(transform.position, targetSpots[currentMoveDirection].position, moveSpeed * Time.deltaTime);
}
}
found from various sources, but in short, thing is I am asking…
how can I find a way to say “If NPC is moving, in this direction, then run this animation of walking, else stop and just do idle”…
any idea how i can accomplish that?