Jump to content

Mob following behavior


RafaMv

Recommended Posts

Hey guys, recently I realized that vanilla mobs have a little delay when they are following a player to attack. It is easy to see if you just walk on circles around the mob. I created a new hostile mob and it seems that this delay is very big, something like a wolf, which would stare at you for some seconds before attacking. Does anyone know where I can fix this behavior by reducing this delay?

Link to comment
Share on other sites

I think it may be related to the AI.  Basically, with computer enemies you usually don't want them to be perfect because then they would be unbeatable.  So in most games the AI only occasionally checks if the non-player character will act.

 

For many entities, they use the "new AI" system that consists of a couple lists of AI task classes which have a priority and also a mutually exclusive masking property.  So for example an entity won't decide to wander or mate if it is in the middle of an attack, etc.

 

For your mob, are you using the AI or are you inheriting AI due to extending an entity class?  If so, then you might need to change the list of AI, possibly replacing with your custom AI, or you can also go back to the "old AI" which was pretty much just writing all your code into the onUpdate() method.

 

Anyway, the first thing I would suggest is to change the priority order of the attack AI tasks.  You can rebuild the AI lists by simply clearing them (they are just a list) and then adding tasks back.

 

I have a tutorial on AI which you might find useful: http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-custom-entity-ai.html

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

Link to comment
Share on other sites

Now I got it working. I don't know why, but my mobs were stopping after moving to the last player position. I think it was priority. Anyway, my AI list is now:

 

 

 

 

this.tasks.addTask(1, new EntityAISwimming(this));

this.tasks.addTask(2, new AIPeck(this));

this.tasks.addTask(3, new EntityAIAttackOnCollide(this, 1.0D, false));

        //This checks a list of items depending on the creature favorite food.

this.tasks.addTask(4, new BygoneAgeEntityAIFollowFood(this, 1.1D, false));

this.tasks.addTask(5, new EntityAIWander(this, 0.85F));

this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 12.0F));

this.tasks.addTask(6, new EntityAILookIdle(this));

 

        //Checks if the creature is adult and tamed.

this.targetTasks.addTask(1, new BygoneAgeEntityAIOwnerHurtByTarget(this));

        //Checks if the creature is adult and tamed.

this.targetTasks.addTask(2, new BygoneAgeEntityAIOwnerHurtTarget(this));

this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));

        //Checks if the creature is adult and tamed.

this.targetTasks.addTask(4, new BygoneAgeEntityAITargetIfNonTamed(this, EntityPlayer.class, 0));

        //Checks if the creature is adult and tamed.

this.targetTasks.addTask(4, new BygoneAgeEntityAITargetIfNonTamed(this, EntityLeptictidium.class, 0));

        //Checks if the creature is adult and tamed.

this.targetTasks.addTask(4, new BygoneAgeEntityAITargetIfNonTamed(this,EntityMoeritherium.class,0));

 

 

 

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.