1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

# Get Killer Distance

Comments in 'Plugin Development' started by JackboyPlay, Feb 3, 2016.

1. Offline

### JackboyPlayActive Member

Joined:
Apr 25, 2015
Posts:
507
Minecraft User:
Hello ich have an question
How can i get the distance frm the "Hitter" to the "victim"?
Example: I will hit Johnson i will get a message "You are {distance} Blocks from Johnson away"
Sorry for the Bad english
2. Offline

### minebuilder0110Notable Member

Joined:
Dec 8, 2014
Posts:
483
Minecraft User:
If there isn't a function for this, I am pretty sure that you should use Pythagorean formula to calculate the distance between two coordinates, and round it.
3. Offline

### PocketKillerNotable Member

Joined:
Jul 20, 2015
Posts:
741
what about \$player1->distance(\$player2); ?
4. Offline

### minebuilder0110Notable Member

Joined:
Dec 8, 2014
Posts:
483
Minecraft User:
Is there is a such function? Hm, I was unaware of it. I was saying about a way to calculate the distance between two players since I did not know such function existed.
(If anyone says I suck because I didn't search, I'm going to be seriously annoyed.)
5. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Use Vector3->distance().
Note that if you just use it for comparison, use distanceSquared() instead of distance(), and compare it with the square of the value you want to compare to. For example, to see if \$vA is at least 4 blocks away from \$vB, you can check `\$vA->distanceSquared(\$vB) >= 16`, where 16 is 4 ** 2.
PocketKiller likes this.
6. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Although many people have no idea what Vector3 is for, it is actually an implementation of most vector operations, including addition, subtraction, scalar multiplication and division, dot and cross product, distance, length and other useful operations.
Don't ask me what dot and cross products are. I referred to my school textbook chapter about vectors, and it only told me how to calculate them without saying what they are/how to use them; but they are very useful, I guarantee. Afaik something to do with matrixes.
PocketKiller likes this.
7. Offline

### JackboyPlayActive Member

Joined:
Apr 25, 2015
Posts:
507
Minecraft User:
Thanks
8. Offline

### Samueljh1H8sLagActive Member

Joined:
Jun 20, 2015
Posts:
168
Minecraft User:
what else would you use distance for?
9. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Display to player?
10. Offline

### JackboyPlayActive Member

Joined:
Apr 25, 2015
Posts:
507
Minecraft User:
Is it possible to check how many blocks a Player Walked in 40 ticks?
If Yes How?
11. Offline

### PocketKillerNotable Member

Joined:
Jul 20, 2015
Posts:
741
one question per thread.
Bluplayz likes this.
12. Offline

### JackboyPlayActive Member

Joined:
Apr 25, 2015
Posts:
507
Minecraft User:
okay