3
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Lærne Sep 13 '14 at 22:11
  • \$\begingroup\$ @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. \$\endgroup\$ – Bennie Godschalk Sep 14 '14 at 9:24
  • \$\begingroup\$ 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 ? \$\endgroup\$ – Lærne Sep 17 '14 at 15:53
  • \$\begingroup\$ If the arrow flies out fast enough why dont you just spawn the arrow slightly above the block? \$\endgroup\$ – Shaun Wild Oct 2 '14 at 14:18
1
\$\begingroup\$

Ex-Bukkit dev here. Not sure if you still want this with the whole bukkit situation...

Really, the only thing to do here is use some tricky packets, to make it not collide, or simply offset the y of where you spawn in up one. You could even use trig to see whee the arrow would fly, and spawn it one block in that direction.

Easiest would be to simply offset it's y coord.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.