Setting eyeLocation/f of a player?

Discussion in 'Plugin Development' started by HyrulesLegend, Dec 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    HyrulesLegend

    I can't seem to figure out if this is possible, does anyone know if it is?
     
  2. Offline

    AoH_Ruthless

    Max_The_Link_Fan
    If you are asking to get the block of the player's head level, just add 1 to the Y of the player's location.

    If you are asking to get their line of sight, there's a specific getLineOfSight() method.
     
  3. Offline

    HyrulesLegend

    AoH_Ruthless I believe it's the line of sight, I'm talking about the direction the player is facing.
     
  4. Offline

    JRL1004

    Max_The_Link_Fan I think this is related to Vectors. I'll look into it for you (since I need this for a plugin I am making).
     
    Max_The_Link_Fan likes this.
  5. Offline

    The_Doctor_123

    Max_The_Link_Fan
    Get the direction of the player's Location by calling getDirection() in Location.
     
  6. Offline

    AoH_Ruthless

    Max_The_Link_Fan
    I think I misread your title by accident, so sorry about that. :oops:
     
  7. Offline

    Zach_1919

    Max_The_Link_Fan I just happen to know a fair bit about vectors. Now when you look up stuff about it, you'll see a bunch of confusing bits and bobs with pitch and yaw and whatnot. This is unnecessary with the Bukkit API. To get a player's vector/velocity, do this:
    Code:java
    1. player.getEyeLocation().getDirection();

    After this, you can manipulate that velocity. Say you want to launch the player forward in whatever direction they're facing. Do this:
    Code:java
    1. player.getEyeLocation().getDirection().multiply(3);

    You can mess around with the 3 and change it to however powerful you want it. Say you want to launch someone straight up. You can do something like this:
    Code:java
    1. player.getEyeLocation().getDirection().add(0,3,0);

    Again, that 3 is interchangeable. You can mess around with the different methods and figure out what you want to do.

    I hope this helped!
     
  8. Offline

    JRL1004

    Zach_1919 WRONG! it's player.setVelocity(/*your stuff*/) if you want that to work
     
  9. Offline

    Zach_1919

    JRL1004 OHH yeah sorry about that, haven't worked with them in a while. Do everything the same that I said, but insert my code into the parenthesis:
    Code:java
    1. player.setVelocity(**MY PREVIOUS CODE**);


    So something like this:
    Code:java
    1. player.setVelocity(player.getEyeLocation().getDirection().multiply(3));
     
  10. Offline

    JRL1004

    Max_The_Link_Fan So I think I made a method to do this, I'll post if it works or not once I test it (which I am about to).
     
  11. Offline

    The_Doctor_123

    JRL1004
    Err.. why..? Vectors are easy enough to work with..
     
  12. Offline

    JRL1004

    The_Doctor_123 Why test? Because even though vectors are simple, I am still human and want to make sure I did not have any mistakes.
     
  13. Offline

    The_Doctor_123

    JRL1004
    You didn't understand what I said correctly. I was meaning to say that you can't really make Vectors any more simple. It's a bit pointless to make a method to do something unless if it's really complicated Vector math.
     
  14. Offline

    JRL1004

    The_Doctor_123 Not true, sometime you just want to be lazy like me and put something like setPlayerEyeLocation(Player, Location) and have it done :)
     
  15. Offline

    The_Doctor_123

    JRL1004
    You positive about those arguments?

    Anyway, as good as it is to take advantage of methods, that's a bit too far.
     
  16. Offline

    JRL1004

    The_Doctor_123 Well I would've had the math within the method to compensate for whatever arguments I choose. As for taking methods too far, what is wrong with making a method for everything I plan to use more than once? If I can get a decent reason not to I will make it a personal goal to cut down on unnecessary methods :)
     
  17. Offline

    The_Doctor_123

    JRL1004
    What you're doing is almost like this:
    Code:java
    1. public int add(int v1, int v2)
    2. {
    3. return v1 + v2;
    4. }
     
  18. Offline

    JRL1004

    The_Doctor_123 Umm not really, I'm not so bad that I use methods for that. My methods are usually from 3 to 30 lines depending on complexity. Of course 3 lines isn't much but it beats one.
     
Thread Status:
Not open for further replies.

Share This Page