# How do i make my dragon my dragon circle a specific blockpos?

## Recommended Posts

This question is more java mathematics related rather than minecraft related, so i plan to make a dragon whistle item that would command a dragon to either fly towards or circle the player when flying, so is my code for making the dragon circle the player and flying correct?

```    protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) { // midpoint is gonna be player position
dragon.setFlying(true);
return dragon.getNavigator().tryMoveToXYZ(midPoint.getX() + 0.5 * Math.PI, midPoint.getY() + 10, midPoint.getZ() + 0.5 * Math.PI, speed);

}```

##### Share on other sites

so﻿ is my code for making ﻿the dragon circle the player and flying correct?

Does the dragon circle the player? And it doesnt look correct to me you are not doing any trigonometry.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

You might want to google “draw circle with points”. I found a stackoverflow answer with a similar search that was very helpful and described how to find points for both an elipse and a circle

Spoiler

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

##### Share on other sites

yes circle above the player

##### Share on other sites

Well, you could store the player's position somewhere within the dragon/AI in addition to the angle variable.

When the AI to circle around kicks in calculate the current angle between these vectors [dragonPos - playerPos], [unitZ](<- I am not sure which direction the game consideres forward, I think it's unitZ though). You can calculate an angle between two vectors using

`arccos((vec1 DOT vec2) / (vec1.length * vec2.length))`

if I am not mistaken.

Then you can start circling, You know the angle the dragon started at so now you can just add to it each tick. The amount you add should be manually tweaked based on your dragon's speed.

Now you have a new angle, which is your previous angle + X. You can then use this angle to calculate the position the dragon needs to be at:

`[x = playerX + r * cos(a), y = playerY + NUM, z = playerZ + r * sin(a)`

Where r is the distance from the dragon to the player you want to acheive(radius of your circle) and NUM is the height of the dragon relative to the player.

Then just tell the dragon to move there.

Edited by V0idWa1k3r
##### Share on other sites

Just now, V0idWa1k3r said:

Well, you could store the player's position somewhere within the dragon/AI in addition to the angle variable.

When the AI to circle around kicks in calculate the current angle between these vectors [dragonPos - playerPos], [unitZ](<- I am not sure which direction the game consideres forward, I think it's unitZ though). You can calculate an angle between two vectors using

```
arccos((vec1 DOT vec2) / (vec1.length * vec2.length﻿))﻿```

what does DOT mean

##### Share on other sites

also would it be good to use this instead of arccos?

`dragon.getDistanceSq(midPoint);`

##### Share on other sites

what does DOT mean

A dot product of two vectors.

also would it be good to use this instead of arccos?

arccos is the operation that is the reverse of the cos operation. The squared distance is just x*x + y*y + z*z. So the answer is no since these are completely different operations.

##### Share on other sites

where is arccos found? Math.class? or MathHelper.class

##### Share on other sites

where is arccos found? Math.class? or MathHelper.class

Should be in Math, but it might be called acost instead of arccos.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

##### Share on other sites

```	protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) {
Vec3d vec1 = new Vec3d(midPoint.getX(),midPoint.getY(),midPoint.getZ());
Vec3d vec2 = dragon.getPositionVector();
double r = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector() ) );
double x = midPoint.getX() + r * Math.cos(dragon.rotationYaw + 90);
double y = midPoint.getY() + 50;
double z = midPoint.getZ() + r * Math.sin(dragon.rotationYaw + 90);
return dragon.getNavigator().tryMoveToXYZ(midPoint.getX() + x, midPoint.getY() + y, midPoint.getZ() + z, speed);

}```

so how'sthis

##### Share on other sites

Vec3d vec1 = new Vec3d(midPoint.getX(),midPoint.getY(),midPoint.getZ());

Vec3d vec2 = dragon.getPositionVector();

Did I tell you "Get the position of the dragon and the position of the center and do things with those vectors"? No, I told you to

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

calculate the current angle between these vectors [dragonPos - playerPos], [unitZ]

And you did none of that. Moving on

double r = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector() ) );

Did I tell you "Oh, the radius of the circle is the angle you calculate"? No, because that makes zero sense. I told you

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

When the AI to circle around kicks in calculate the current angle between these vectors

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

Then you can start circling, You know the angle the dragon started at so now you can just add to it each tick.

Moving on

double x = midPoint.getX() + r * Math.cos(dragon.rotationYaw + 90);

Did I tell you "Use the dragon's rotation yaw plus an arbitrary number as an angle"? No, because unless you are rotating your dragon that makes no sense(and if you are - it is always looking away from the player and moves sideways). I told you to

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

Now you have a new angle, which is your previous angle + X. You can then use this angle to calculate the position the dragon needs to be at

Moving on:

return dragon.getNavigator().tryMoveToXYZ﻿(midPoint.getX() + x, midPoint.getY() + y, midPoint.getZ() + z, speed);

So you have 2 vectors - midPoint and your [x, y, z]. [x, y, z] is midPoint + someNumbers. If you add them together you are essentially doubling the midPoint vector(kinda). So if your dragon is at [200, 100, 200] you are telling it to move to ~[400, 250, 400]. I don't think that it is what you want and that is not what I told you.

##### Share on other sites

also what is this "a" for

`playerX + r * cos(a)`

##### Share on other sites

also what is this "a" for

```
playerX + r * cos(a)```

If r is radius then I assume a is angle

Spoiler

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

##### Share on other sites

```	protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) {
Vec3d vec1 = new Vec3d(midPoint.getX(),midPoint.getY(),midPoint.getZ());
Vec3d vec2 = dragon.getPositionVector();
double a = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector()));
Vec3d r = vec1.subtract(vec2);
double x = midPoint.getX() + r.x * Math.cos(a);
double y = midPoint.getY() + 50;
double z = midPoint.getZ() + r.z * Math.sin(a);
return dragon.getNavigator().tryMoveToXYZ(midPoint.getX() + x, midPoint.getY() + y, midPoint.getZ() + z, speed);

}```

##### Share on other sites

Vec3d vec1 = new Vec3d(midPoint.getX(),midPoint.getY(),midPoint.getZ());

Vec3d vec2 = dragon.getPositionVector();

6 hours ago, V0idWa1k3r said:

calculate the current angle between these vectors [dragonPos - playerPos], [unitZ]

You are still not doing that.

double x = midPoint.getX() + r.x * Math.cos(a);

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

r is the distance from the dragon to the player you want to acheive(radius of your circle)

Where did you get the impression that radius is somehow a vector?

return dragon.getNavigator().tryMoveToXYZ(midPoint.getX() + x, midPoint.getY() + y, midPoint.getZ() + z, speed);

6 hours ago, V0idWa1k3r said:

So you have 2 vectors - midPoint and your [x, y, z]. [x, y, z] is midPoint + someNumbers. If you add them together you are essentially doubling the midPoint vector(kinda). So if your dragon is at [200, 100, 200] you are telling it to move to ~[400, 250, 400]. I don't think that it is what you want and that is not what I told you.

##### Share on other sites

```	protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) {
Vec3d vec1 = new Vec3d(midPoint.getX(),midPoint.getY(),midPoint.getZ());
Vec3d vec2 = dragon.getPositionVector(); // "calculate the angle between these 2 vectors" I think this im missing and im bad a t trigonometry

double a = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector()));
double r = dragon.getDistanceSqToCenter(midPoint);  // radius is now a double
double x = midPoint.getX() + r * Math.cos(a); // x = playerX +﻿ r * cos(a) as stated
double y = midPoint.getY() + 50; // y = playerY + NUM as stated
double z = midPoint.getZ() + r  * Math.sin(a); //  z = playerZ + r * sin(a) as stated
return dragon.getNavigator().tryMoveToXYZ(x, y, z, speed);  	// no more adding

}```

##### Share on other sites

Well, the only thing that you are missing right now is

On 11/27/2018 at 7:06 AM, V0idWa1k3r said:

these vectors [dragonPos - playerPos], [unitZ]

What I am saying is vec1 is [dragonPos - playerPos] and vec2 is [unitZ]. This

double a = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector()));

Is the line that calculates the angle, you just need to get the vec1 and vec2 right.

Also this

double r = dragon.getDistanceSqToCenter(midPoint);

is a squared distance, as the name of the method implies. Have your radius be a constant or something, this will make your dragon fly away from the player at an exponential rate.

Edited by V0idWa1k3r
##### Share on other sites

what does unitZ mean?

d
##### Share on other sites

what does unitZ mean?

##### Share on other sites

```protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) {
Vec3d﻿ vec1 = dragon.getPositionVector().subtract(midPoint.getX(),midPoint.getY(),midPoint.getZ());
Vec3d vec2 = dragon.getPositionVector(); // what does unitZ mean

double a = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector()));
double r = 12;  // radius is now a constant
//    double r = dragon.getDistance(midPoint.getX(),midPoint.getY(),midPoint.getZ()); can i use dis?
double x = midPoint.getX() + r * Math.cos(a); // x = playerX +﻿ r * cos(a) as stated
double y = midPoint.getY() + 20; // y = playerY + NUM as stated
double z = midPoint.getZ() + r * Math.sin(a); //  z = playerZ + r * sin(a) as stated
return dragon.getNavigator().tryMoveToXYZ(x + 0.5, y + 0.5, z + 0.5, speed);      // no more adding

}```

##### Share on other sites

what does unitZ mean?

[0, 0, 1]. But I don't atually know what direction the game considers the forward one, so it might be some other unit vector.

##### Share on other sites

its z of course, in models z is forward or back ward, by [0,0,1] you mean; new Vec3d(0,0,1) or new BlockPos(0,0,1)

##### Share on other sites

new Vec3d(0,0,1) or new BlockPos(0,0,1)

The only difference between these two is that the first one uses doubles while the second one uses ints. You need the double one.

its z of course, in models z is forward or back ward

It should be, but I wouldn't count on that.

##### Share on other sites

```	protected boolean tryToCircleBlockPos(BlockPos midPoint, double speed) {
Vec3d vec1 = dragon.getPositionVector().subtract(midPoint.getX(),midPoint.getY(),midPoint.getZ());
Vec3d vec2 = new Vec3d(0,0,1); // "calculate the angle between these 2 vectors" I hope vec3d is compat with Blockpos Vec3i

double a = Math.acos((vec1.dotProduct(vec2)) / (vec1.lengthVector() * vec2.lengthVector()));
double r = 12;  // radius is now a constant
double x = midPoint.getX() + r * Math.cos(a); // x = playerX +﻿ r * cos(a) as stated
double y = midPoint.getY() + 20; // y = playerY + NUM as stated
double z = midPoint.getZ() + r * Math.sin(a); //  z = playerZ + r * sin(a) as stated
return dragon.getNavigator().tryMoveToXYZ(x + 0.5, y + 0.5, z + 0.5, speed);  	// no more adding
}```

they do go to me, but they dont rotate on a position, am i doing something wrong, does this needs to be a static or a loop?

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

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

• ### Posts

• It looks like it's cause by Epic Fight, but I used it before and it worked
• Good morning/afternoon/night, I was playing minecraft modded an entire modpack of 300+ mods and after spending days on it i began getting crashes something related to farmer_environmental:forest at first i found a way to just remove the mod it was part of which was immersiveengineering at first then it was related to blue skies, I did the same removed it as well but now it's on minecraft itself. Anyone got any clues on how to fix this issue? Cheers. Here's the pastebin of the crash log: https://pastebin.com/7wC4Q3bv

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...