# [1.7.10] Getting item to drop directly in front of player no matter what

## Recommended Posts

Hi everyone,

I guess this is more of a math question really, I want to drop an item directly in front of my player no matter what his position is or rotation. I have the players position x1,y1,z1 and I want to drop the item at x2,y2,z2 so that these coordinates (where i drop the item) are always located directly in front of my player. The player has a rotation yaw and rotation pitch I was wondering if there is a way to use these values to determine the "forward coordinates" x2,y2,z2 where my item should drop so that they always exist in front of the player. Any ideas?

##### Share on other sites

I believe the easiest way to do it is to use vectors. Minecraft has a 3D vector class called Vec3 which basically just contains an x, y, z but also includes methods for adding, normailizing, etc.

Anyway, there is a thing called the "look vector" which Minecraft maintains that indicates a normailzed (length of 1) vector in the direction the entity is facing. So if you want to find a position in front of an entity, the math is pretty simple:

1) Make a new Vec3 using the player position.

2) Get the player look vector multiplied by the distance you want it to be in front of the player.

3) Add the two vectors from step #1 and #2 together -- the x, y, z will be a position in front of the player.

Note that in 1.7.10 to create a new Vec3 you have to use the vector helper method, but in 1.8 you can just construct them directly.

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

##### Share on other sites

Can this happen on server side since I need it to happen server side

##### Share on other sites

also where would I access the look vector is that obtained by using

` MovingObjectPosition mop= player.rayTrace(5, 1.0F);`

(cause this is client side only and I need this vector on server side) is there a way to get the look vector server side to avoid a packet.

and ya to make a vector in 1.7.10 you need to do

```Vec3 vec = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
```

##### Share on other sites

found it for those that are reading you can get the look vector on server by doing

```
Vec3 vec3 = player.getLookVec();

```

##### Share on other sites

In not sure about th emath but this is definately wrong...

```
Vec3 lookVector = player.getLookVec();
lookVector.xCoord = lookVector.xCoord * 1.5;
lookVector.yCoord = lookVector.yCoord * 1.5;
lookVector.zCoord = lookVector.zCoord * 1.5;
```

I want the distance to be 1.5 away from the player but it isnt

##### Share on other sites

You don't want a vector, though, you want world coordinates: add the vector coordinates to the player's position, not the player's position to the vector:

```Vec3 look = player.getLookVec();
float distance = 1.5F;
double dx = player.posX + (look.xCoord * distance);
double dy = player.posY + player.getEyeHeight(); // notice I'm not using the vector here: if the player is looking straight down, the item would end up in the ground
double dz = player.posZ + (look.zCoord * distance);
// now spawn your entity with (dx, dy, dz) as its position
```

##### Share on other sites

that worked perfectly thanks everyone

##### Share on other sites

You don't want a vector, though, you want world coordinates: add the vector coordinates to the player's position, not the player's position to the vector.

Actually, adding the vectors works too. A Vec3 is really just an x, y, z coordinate. It is a "vector" if you consider it's origin to be relative, but it is an absolute position relative to the world origin. So the way he added the vectors would work as well. The final position would just be the xCoord, yCoord, zCoord of the resulting vector.

But I did forget to discard the Y part of the vector. Good catch.

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

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

• Hi, I have the oficial launcher using the version 1.21, and forge 51.0.13, as soon as I start the installation the games crashes and gives me "exit code: 1", I haven't put any mods yet in the folder. Its the second time that uninstall and install everything and nothing works, checket my graphics and they are updated. https://pastebin.com/STPgEiVs   thanks!
• Ty very much it worked
• no clue what is going on, you guys seem more knowledgeable than I am. So here's my log as well as my mod list. Error Folder On Google Drive

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

×

• #### Activity

×
• Create New...