For simple game i'm making for learning purpose, i'm trying to make the character move from point A to point B.
I've already tried some things but the only way i've found is to make go to X value of point B then to the Y value
public void Walk(Vector2D target)
{
var distance = Character.Position.Distance(target);
bool positiveX = target.X > Character.Position.X;
bool positiveY = target.Y > Character.Position.Y;
for (var i = 0; i < distance.X; i++)
{
var position = Character.Position.Clone();
position.X = (positiveX ? 1 : -1) + position.X;
if (Map.IsWalkable(position))
{
Character.Move(position);
}
}
for (var i = 0; i < distance.Y; i++)
{
var position = Character.Position.Clone();
position.Y = (positiveY ? 1 : -1) + position.Y;
if (Map.IsWalkable(position))
{
Character.Move(position);
}
}
}
I would like to make the character "walk" in diagonal when needed
Like in this image