Jump to content

[1.7.2] Hovering mob AI


Eastonium

Recommended Posts

Hi, I need some sort of AI for a mob I have that will make it hover above the ground about 4 blocks.

I'm not sure how to accomplish this. I don't think I need a new AI class, I can just put it in my onLivingUpdate() method.

I know there are some things like getEntityPosition, but I don't know how to utilize these as I don't know how to use the Vec3 object type.

If anyone could help, that'd be great!

Link to comment
Share on other sites

With entity AI, computers are so much faster than humans that you need to purposely limit their decisions to be less frequent.  You don't want to use onLivingUpdate() because I think that gets updated every tick (20 times per second).  Instead, if you think how entities in Minecraft act, they change their behavior only every couple seconds or so.

 

It is actually pretty easy to use the AIBase class and use an AI tasks list.  I suggest you just look at other vanilla entities like Wolf and Bat to see how they do it.

 

Basically you create a list of tasks that are done in certain order every once and a while and it will call your custom AI class.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I've looked at a lot of AI now, but I haven't found anything that'd be much of a help.

The only thing I found is the updateAITasks() method that runs at the same rate of AI tasks, so I won't be using the onUpdate() for the flying if I ever figure it out.

At least I think that would work. I tried something but when it was "hovering" it never did any of the other AI tasks...

Link to comment
Share on other sites

Most of the AI I've done have been pretty simple modfications (like making entities target different things than vanilla entities).

 

However, I do suggest you use the AI tasks list method.  Look at a class like EntityWolf to see how the list is created.

 

Then you further want to create your own AI class that extends AIBase and then put that in the AI tasks list of your entity.

 

In your AI class you'll have to put in whatever code you want to control your Entity, but if you want it to move you can have it check for a free path in the direction you want to go and then update the position over time accordingly.

 

To get started, you can make a simple AI that will cause it to move upwards a few blocks from where it spawns.  Basically you can just have a starting Y position saved in a variable of the Entity constructor and then in your task you can update the actual Y position until it is some number higher.  That should get it off the ground at least. 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Take a look at some flying entities to see how they use flight paths (such as the Ghast or Bat); you should be able to adapt that to your needs, taking into account the new position's height above the ground and such as needed, possibly even giving your mob some leeway so it can fly anywhere between 1-4 blocks above the ground, rather than always 4.

 

One advantage of using a flight path is you can calculate a target coordinate and then let the mob move without re-checking the flight path until it arrives or gets close to the destination; this is nice if your flight calculations are complicated, but you may also want to allow the path to be interrupted say if the mob is attacked or a player comes near (like with bats).

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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