Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I make an entity walk in a straight line at the direction in which it's looking?

Featured Replies

Posted

I want to make an entity that is able to walk in a straight direction where it's looking, and stop either when the path if obstructed (e.g. there's lava) or when a timer runs out, however I don't know where I could begin.

Look at MoveToBlockGoal and rework it.

i.e. Replace findNearestBlock() with your own logic.
 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

Sorry for the late reply, was doing stuff.

 

So how exactly would it work? Let's say, I want the entity do play an animation, walk in a straight line, then stop at its tracks when the path in front of it is blocked. 

 

I'm also having some trouble trying to get where the entity is facing and set a straight line for it to walk there.

Quote

So how exactly would it work? 

We are not going to write your mod for you. This is a support forum not a teaching forum.

 

Quote

Let's say, I want the entity do play an animation, walk in a straight line, then stop at its tracks when the path in front of it is blocked. 

You need to look at that code I suggested above.

It's part of the entity AI code which has builtin entity PathNavigation and MoveControl you can use.

 

Quote

I'm also having some trouble trying to get where the entity is facing and set a straight line for it to walk there.

It depends what you mean by "facing".

There is an entity.getViewVector() that tells you which direction the entity is looking

or there is also the LivingEntity's body rotation, see Panda.afterSneeze() for an example usage of this.

 

You can also do "ray tracing" to see what an entity is looking at, e.g. Entity.pick()

This part of your question has been asked and answered in many posts of this forum, so search is your friend if you want a longer answer to this FAQ.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.