# [Vector Math] Getting the block the player is looking at with precise collision point

Discussion in 'Plugin Development' started by Ziden, Oct 5, 2014.

Not open for further replies.
1. Offline

### Ziden

Hi !

The goal of this is to play an effect, in a line, from where the player is lookin at to a point, and this is already done:

Code:
```Vector bulletVector = GunMechanic.getShootVector(p, getRange());

// calculating the locations
Location begin = p.getEyeLocation();

Block target = p.getTargetBlock(null, getRange());
if(target!=null) {
p.getWorld().playEffect(target.getLocation(), Effect.STEP_SOUND, target.getTypeId(), 3);
}
GunMechanic.effectLine(Effect.PARTICLE_SMOKE, begin, end, 20);```
However, this aways draws the effect at maximum range.

I can detect the block the player is lookin at and set the end position to it, but it will tweak the line a little bit to fit integer values of the block zyx while the vector draws precisely with double values.

So i need to know , the exact collision point that the player eye vector has with a block so i can do a precise draw of the particle effect line.

Does anyone knows how to perform this ?

#1
2. Offline

### Skionz

You can do something like this
Code:java
`Location loc = player.getLocation();loc.add(loc.getDirection().multiply(10));`

Gets the exact point the player is looking at 10 blocks away. You could just increment the value.

#2
3. Offline

### MnMaxon

Ziden
Code:java
`// Vector bulletVector = GunMechanic.getShootVector(p, getRange()); - I don't know what this is // calculating the locationsLocation begin = p.getEyeLocation();Location end = begin;double range = getRange();while(!end.getBlock().getType().isSolid() && end.distance(begin) < range) {end = end.add(p.getLocation().getDirection().multiply(.1));} // I didn't change anything below thisBlock target = p.getTargetBlock(null, getRange());if(target!=null) {p.getWorld().playEffect(target.getLocation(), Effect.STEP_SOUND, target.getTypeId(), 3);}GunMechanic.effectLine(Effect.PARTICLE_SMOKE, begin, end, 20);[FONT=Georgia][/FONT]`

I'm not really sure what bulletVector was, so I ignored it. I also assumed getRange() was a double.

If you have any questions about it, or my assumptions were wrong, tell me.

#3