Jump to content

[1.7.10] Mob Pathing and Custom Movement Control


Thornack

Recommended Posts

Ok So I have been playing around with this and have written an AI that makes entities wander around in a square indefinitely. The problem is the square can only be a max of 15 x 15 (entities wont move if it is 16 x 16 in size or greater) and I would need this limitation taken off. I started out with a straight line and for that too the entities can only move up to 15 blocks in whatever direction I specified (but if I set it to 16 or higher they dont move at all and this is a problem. I was wondering if anyone has any ideas on how to remove this distance limitation.

 

Also, the entity does not align itself with the vector perfectly which results in ridiculous looking behaviour (for bipeds as an example the legs move in the X directions but the entity moves in the Z direction or slightly off the X direction and this makes the walk look really weird. Any ideas?

 

 

My eventual goal to be achieved from this playing around with AI's and entity motion:

 

I want to figure out a way to make them move in a shape that I specify via an item that obtains the worlds coordinates at each block I click where clicking subsequent blocks would "draw the path of the entity" but for now baby steps.

 

My EntityAICustomWander class that I have been messing around with to try and understand vectoring and entity movement

 

 

public class EntityAICustomWander extends EntityAIBase

{

    private EntityCustom entity;

    private double xPosition;

    private double yPosition;

    private double zPosition;

    private double speed;

    private boolean isExecuting;

    private int state = 0;

 

    public EntityAICustomWander(EntityCustom entityCustom, double par2)

    {

        this.entity = entityCustom;

        this.speed = par2;

       

  // To make an AI compatible with swimming, begging and watching closest then you should set mutexBits to 1.

  // To make an AI compatible with swimming, but not begging and watching closest you should set mutexBits to 3.

  // To make an AI compatible with begging and watching closest, but incompatible with swimming you should set mutexBits to 5.

  // To make a new AI that is compatible with everything vanilla, then you can choose to set mutexBits to 8 (or any larger power of 2).

  // To make a new AI that is incompatible with everything vanilla, then you should set the mutexBits to 7.

        this.setMutexBits(1);

    }

 

    /**

    * Returns whether the EntityAIBase should begin execution.

    */

     

    public boolean shouldExecute()

    {

        if(this.isExecuting)

        return false;

         

        Vec3 vec3 = null;

        switch(state){

            case 0:

            vec3 = Vec3.createVectorHelper(this.entity.posX+15,this.entity.posY,this.entity.posZ);

            break;

            case 1:

            vec3 = Vec3.createVectorHelper(this.entity.posX,this.entity.posY,this.entity.posZ+15);

            break;

            case 2:

            vec3 = Vec3.createVectorHelper(this.entity.posX-15,this.entity.posY,this.entity.posZ);

            break;

            case 3:

            vec3 = Vec3.createVectorHelper(this.entity.posX,this.entity.posY,this.entity.posZ-15);

            break;

            }

       

            if (vec3 == null)

            {

                return false;

            }

            else

            {

                this.xPosition = vec3.xCoord;

                this.yPosition = vec3.yCoord;

                this.zPosition = vec3.zCoord;

                this.isExecuting = true;

                return true;

            }

        }

 

    /**

    * Returns whether an in-progress EntityAIBase should continue executing

    */

    public boolean continueExecuting()

    {

        if(this.entity.getNavigator().noPath()){

        this.isExecuting = false;

        this.state++;

        if(state == 4)

        state = 0;

        return false;

        }

    return true;

    }

    /**

    * Execute a one shot task or start executing a continuous task

    */

    public void startExecuting()

    {

        this.entity.getNavigator().tryMoveToXYZ(this.xPosition, this.yPosition, this.zPosition, this.speed);

    }

}

 

 

Link to comment
Share on other sites

Okay, if you look through the navigator code for the tryToMoveToXYZ() method and look closely you'll see that the navigator has a search range and that search range is set in the constructor of the navigator to equal the followRange attribute of the entity.

 

So I think (not certain, but try it) that if you set the followRange attribute of your entity to be larger, then the pathfinding can go farther.  However, you should be careful as I assume if you make the range much larger that it could start to create lag as the number of possible paths would grow in the case of trying to find a path in a complicated terrain (like in a forest with a lot of trees as obstacles).

 

Anyway, try increasing the followRange of your entity.

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

Link to comment
Share on other sites

  • 3 weeks later...

Ok So I have had a breakthrough in this topic. I tried Jabelar's suggestion and it works, this seems like a really inefficient way to implement this functionality though.

 

Basically all that it took was adding this code to the entity file of whatever entity I wanted to extend its range. I am now looking at trying to figure out a way to calculate a movement vector for my entity based on in game coordinates that are specified by a player (ie have a player click on a block and use those coordinates to calculate a movement vector for the entity so that it moves to where the player clicked)

 

protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100.0D);
        //this distance controls how far you can make a mob move. the value can be up to 2048 but the larger the value the more paths are possible so the game will lag if the value is too large   
    }

Link to comment
Share on other sites

I have been looking into  this topic further and also into ray tracing. is there a way to get the coordinates of a block based on a ray trace. I plan to use those coordinates inside a function to get an entity to move to whichever coordinate I specify by the ray trace. I know that the following line gets a ray trace vector

//Gets the ray trace vector from the player using the arguments  distance, partialTickTime
		MovingObjectPosition movingObjectPosition = player.rayTrace(5, 1.0F);
[code]

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.