# Solved Spawning a arrow at 1 point and having it land in another

Discussion in 'Plugin Development' started by Lightspeed, Sep 27, 2015.

Not open for further replies.
1. Offline

### Lightspeed

I have a system to create 2 points and then have the arrow shoot from p1 to p2 with it having a vector of 2 for the y. Anyway I can figure out how much speed I need for it to land there?(All my ways fail or only work for a certain amount of block and then it's off by a few pixels)
What I need is for it to arc and hit the target.

What I use to spawn snowball*edit*Arrow oops
Code:
```double speed = 0.202; //speed to get from p1 to p2 (1block)
Arrow sb = p.getWorld().spawnArrow(p1, p3.add(new Vector(0, 3, 0)), (float) speed, 0);```
p1 and p2 are 2 different locations
p3 is a vector facing p2 from p1

#1
2. Offline

### RoboticPlayer

I think you might have to do some trig to get this, but don't quote me on that.

#2
3. Offline

### Lightspeed

I need some code or ideas(like what you said) I got no clue how to do this XD

#3
4. Offline

5. Offline

### Lightspeed

I used the first link to get direction
The second link dosen't work unfortuntly :c
*Edit the second link works but not for what Im doing.*
I need to calculate the speed required to make the arc not a vector.
The arc is as high as the lenght*note*

Last edited: Sep 27, 2015
#5
6. Offline

### ChipDev

Easy trig, but hard gravity

#6
7. Offline

### 567legodude

@Lightspeed @ChipDev If you can figure out what the acceleration of gravity is in MC, then it is pretty easy to calculate the values to get from point A to point B. And since there is no wind resistance, it it even easier.
I may actually run some tests myself to find out what it is.

#7
8. Offline

#8
9. Offline

### Pocketkid2

Your best bet would be to follow that guide in calculating parabolic motion vectors. That's a better method, and I'd definitely do that if I were you. Even if you don't want to, I'm sure you could figure out how to use the information to find what you need.

#9
10. Offline

### blablubbabc

Actually, there is 'wind resistance' in minecraft: Every tick the moving entity gets applied 'drag'. You can find the gravity (acceleration), drag and final velocities for the different entities in the minecraft wiki: http://minecraft.gamepedia.com/Entity#Motion_of_entities

So the final entity movements (especially for movements further than a few blocks) isn't a perfect arc, but looks more like what you can see on the images here: https://en.wikipedia.org/wiki/Trajectory_of_a_projectile

However, it becomes difficulty trying to apply the official projectile trajectory formulas, because those require parameters which we don't know the exact equivalents for minecraft.

So, if you know at which (initial) speed you want to launch your arrow, a different attempt for finding a good initial launching angle would be what I am explaining here. This works pretty well for longer ranges (100+ blocks).
Though the shown code there, while it seems to work quite well, is slightly outdated already: I have applied some improvements to it in the meantime (those mostly affect the table creation and how the gaps between different curves and for fast projectiles are filled) though I wasn't yet able to test those improvements and verify their correctness. But the basic idea is still the same.

#10
11. Offline

Bump

#11
12. Offline

### mythbusterma

@Lightspeed

Did you even read the post above yours before saying that? Do you realise how ridiculously ignorant you look? He answered your question.

#12
13. Offline

#13
14. Offline

#14
15. Offline

### Lightspeed

I know
I had a question about it but, I just needed to think to get my awnser . . . I do this somtims XD

#15