#Vectors Help

1 messages · Page 1 of 1 (latest)

agile lark
#

So I've been trying to make a triple shot bow/gun and I need to find a way to move the arrows a bit to the left/right (+/- 1 to the x) based on the position of the center arrow

Here's my current code:

#
Vector arrowDirection = player.getLocation().getDirection();

                    Entity arrow = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection), Arrow.class);


                    Entity arrow2 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(1,0,0), Arrow.class);
                    Entity arrow3 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(-1,0,0), Arrow.class);```
                                                                                                                                                                                                              ^  this part needs fixing ^
amber jungle
#

mmm wouldnt you want to use the player's Y and Z? - me goes to check add. for vectors

leaden parcel
#

what is not working right now?

agile lark
#

on certain sides it just shoots 3 arrows in one spot (not spreading them)

leaden parcel
#

I see

amber jungle
#

doesnt getEyeLocation only return the level of the eyes and not the direction?

agile lark
#

im using eyelocation to get the direction the player is looking at, then adding one block forward so the arrows dont spawn in the players head and hurt it

leaden parcel
#

Another solution would be to use

Entity arrow2 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(0.5,0.5,0.5), Arrow.class);
Entity arrow3 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(-0.5,-0.5,-0.5), Arrow.class);

instead

#

Actually if you shoot diagonally that won't help either

amber jungle
#

but you are not using the Location with yaw and pitch ...

leaden parcel
#

now that should help

leaden parcel
amber jungle
#

the other doesnt return direction

leaden parcel
#

The pitch/yaw is inherited from the player's pitch/yaw

agile lark
#

yaw and pitch are weird sometimes and they cause performance issues so i just avoid using them

leaden parcel
#

Oh, the player would damage itself there

amber jungle
#

also without pitch wouldnt the two extra arrows go flat instead of up/down ?

leaden parcel
#

Either you slightly nudge the pitch/yaw or you change your 1 block offset to be based around the pitch yaw, however at that point you still get the sin/cos calls

leaden parcel
agile lark
#

^ i want the arrow

amber jungle
#

wondering though can you not use the bow event and use getProjectile to duplicate the arrows?

agile lark
#

                    double x = arrowLocation.getX();

                    Entity arrow2 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(x +1,0,0), Arrow.class);
                    Entity arrow3 = player.getWorld().spawn(player.getEyeLocation().add(arrowDirection).add(x -1,0,0), Arrow.class);```

maybe this would do?
#

ill try it ig

leaden parcel
#

no

amber jungle
#

Playing with thing, i think you might be looking for:

p.getWorld().spawnArrow(arrowOrigin, (arrowOrigin.subtract(arrowTarget)).toVector(), arrowForce, arrowSpread);

That should allow each arrow to hit the target, or at least close to it