How can I make a villager *walk* to a certain location?

Hello!

Imagine I have a command X. When I issue it, I want a certain entity (villager) walk to a certain location.

Not teleport, but walk, i. e. move to the location in the time it normally takes him in Minecraft. It’s important for me to make this walking more or less natural because I need this for a certain simulation and it’s convenient to see what that villager is doing at the moment.

How can I make a villager walk from location X to location Y?

Thanks

Dmitri

Um AI and stuff… Not sure if that is exposed yet, but @zidane would know, as he’s the one working on the AI API.

1 Like

@Socratic_Phoenix I don’t need any AI because the target location is right in front of the villager, nothing complicated. I’m asking about what code I need to write in order for the villager to start moving so that I can see it.

What I want is this:

  1. Villager X stands at location Y (Y is some distance away from X but he just needs to go straight to it, no turns).
  2. I issue some command.
  3. Thereafter X makes several steps forward, such that I can see it (I can see, how he walks to the target destination and this happens with the same speed, as if a human would control him).

You do need the AI, because it’s the AI that tells the villager to walk.

You could make a villager with no AI, and run a task every tick that teleports him forward a bit… You’d have to do vector math and stuff if you want it to work in every case.

2 Likes

OK, let’s say I don’t want to spend time on implementing walking and I’m content with just teleporting the villager to that location.

But I still want to make it in such a way that the player can see it (i. e. it shouldn’t happen too fast).

For that I could build

a) some sort of queue with command objects (command would be something like “move entity X to place Y not earlier than time Z”) and

b) a scheduled task, which is called regularly, looks into the queue and executes all commands from a), whose time has come.

Do I have to implement it myself or should I use some existing infrastructure for this?

Yes, you’d have to implement something like what you’re talking about, or you’d have to wait for the AI framework to be finished.

Edit: But what you’re talking about doesn’t seem horribly difficult anyway…

1 Like

To nagivate from point A to point B, you will need some form of pathfinding.
However, to player the actual walking animation, you can simply teleport the entity a small distance in the proper direction. This causes the client to render the walking animation.

2 Likes