So I have 2d isometric game , I am using a grid graph with the following values:
I have a agent which is a 2 sprite (with some animation), I have follower entity on the agent for its movement, this is how I have moving it in script:
public IEnumerator moveUnitTo( Vector3 location, bool manualControl) {
this.moving = true;
this.followerEntity.updateRotation = false;
this.followerEntity.DrawGizmos();
this.isBeingOrderedByRuler = manualControl;
NNInfo targetNode = MapManager.Instance.aStarGridGraph.GetNearest(location, NNConstraint.None,1000f );
this.followerEntity.SetDestination(getClampedPosition(targetNode.position));
// Not sure if this is the best way to do this
while (true) {
this.followerEntity.updateRotation = false;
// Animates and sets direction of the sprite
animateUnitMove();
if ((this.followerEntity.reachedDestination || this.followerEntity.reachedEndOfPath)) {
break;
}
yield return new WaitForEndOfFrame();
}
this.moving = false;
this.isBeingOrderedByRuler = false;
}
private void animateUnitMove() {
int decimalPlaces = 2; // Number of decimal places to round to
float speed = Mathf.Round(Mathf.Clamp(this.followerEntity.velocity.magnitude, 0, 1) * Mathf.Pow(10, decimalPlaces)) / Mathf.Pow(10, decimalPlaces);
// face the unit ideal in last walking direction
if (speed > 0.02) {
animator.SetFloat("vertical", Mathf.Clamp(this.followerEntity.velocity.y, -1, 1));
animator.SetFloat("horizontal", Mathf.Clamp(this.followerEntity.velocity.x, -1, 1));
}
animator.SetFloat("speed", speed); // determines if the unit is walking or ideal
}
So the unit moves fine with its moving horizontal but not so much when it moving veritically , this is what I mean :
I think it still rotating and when it moves up and down the rotation some how gets messed up, not sure why this is happening though, and only for moving up and down