# Edit spawn location according to vector direction

I'm trying to make a turret in Bukkit (Java). This will shoot an arrow to the players that are in the shooting radius. But now I've a little problem, the arrow gets stuck inside the block where its spawned. Now I'm trying to spawn the arrow at the side of that block so it wont get stuck anymore, but I don't know how to calculate the best side of the block to set the new spawn location. Like North, East, South or West of the block.

So is there someone who can help me with this? Thnx!

Code that I use for now:

Vector v = pl.getLocation().add(0, 2, 0).toVector().subtract(loc.toVector());
Arrow arrow = (Arrow) Bukkit.getWorld(loc.getWorld().getName()).spawnArrow(loc, v, (float) 4, t.getAccuracy());


So the variable loc needs to be recalculated so it will be outside the block to the right direction from the vector 'v'.

• You have a multiply(1) in your code, which mathematically speaking is 100% useless. Anyway is you game tiled-based. Or just the scenery and the character can move continuously ? That would make a small difference. – Lærne Sep 13 '14 at 22:11
• @Lærne The game runs in minecraft, the turret stands still and is the 2nd block of the turret. The targets can move in x, y, z. But the new location has only to be changed in x and z. I can't make it that it shoots the arrow 1 block above the turret because than it can get stuck in a block above the turret xd Picture of the turret: g2f.nl/0ztrywe, g2f.nl/09bao73. The arrow comes out the fence. – Bennie Godschalk Sep 14 '14 at 9:24
• You need to check whether x > z or otherwise and whether x > -z. x==z and x==-z are the equation of the two diagonals that goes through the horizontal planes of the block assuming the block center lies in (0,0,0), so you need to translate coordinates if needed. Knowing this, you can determine in which quadrant is the player and create the arrow in the neighbor block of the corresponding quadrant. Cannot help more, your code uses unclear variables. What is loc ? A location. Of what ? pl ? A player ? and t ? – Lærne Sep 17 '14 at 15:53
• If the arrow flies out fast enough why dont you just spawn the arrow slightly above the block? – Shaun Wild Oct 2 '14 at 14:18