player.teleport()

Discussion in 'Plugin Development' started by Vincent1468, Jul 23, 2013.

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

    Vincent1468

    Hello,

    I've got a question about teleporting. When I teleport a player multiple times the pitch and yaw stay the same, this looks really ugly. So is there a way to teleport a player multiple times while the player can freely look around?

    Thanks.
     
  2. Offline

    NoLiver92

    what about creating a location without the pitch and yaw?

    there are 2 ways of defining a location:
    1) Location(world,x,y,z,pitch,yaw)
    2) Location(world,x,y,z)

    define the location like the second option
     
  3. Offline

    Vincent1468

    NoLiver92

    Thanks for your reply, but I've tried that and it didn't work.
     
  4. Offline

    Vincent1468

    Bumping this :)
     
  5. Offline

    Dpasi314

    Vincent1468
    I'm not quite sure what you're asking? While teleporting a player multiple times you want them to be able to look around? Is there a delay in the teleport, because I don't think that you can have them look around because the code is executed so fast. Sorry, again not quite sure what you're asking =P
     
  6. Probably not do-able without doing some weird pseudo stuff, like set the pitch and yaw to the previous pitch and yaw. You could do that by saving them, and loading them on teleport. Not sure if and how that would work though.
     
  7. Offline

    Vincent1468

    Dpasi314

    I've got two locations, and a list of locations between those two locations. I want to teleport the player from location one to location two, but the pitch and yaw stay the same and because of that it looks really ugly.
     
  8. Offline

    Dpasi314

    Ah, well what NoLiver92 said about setting the pitch and yaw, SHOULD ideally be working assuming the rest of your code is correct.
     
  9. Offline

    Vincent1468

    Dpasi314
    Well I tried what he said before posting this topic, but sadly, it didn't work.
    Here is how I teleport the player:
    Code:java
    1. for(int i = 0; i < tLocs.size(); i += 6) {
    2. final Location l = tLocs.get(i);
    3. Bukkit.getScheduler().scheduleSyncDelayedTask(ImeSpawn.getPlugin(), new Runnable() {
    4.  
    5. @Override
    6. public void run() {
    7. p.teleport(l);
    8. try {
    9. ParticleEffect.sendToLocation(ParticleEffect.EXPLODE, l.add(0, -1, 0), 0.25F, 0.25F, 0.25F, 0.25F, 16);
    10. } catch(Exception e) {
    11. e.printStackTrace();
    12. }
    13. }
    14.  
    15. }, i * 1);
    16. }
    17.  

    And I add the locations like this:
    Code:java
    1.  
    2. World w = Bukkit.getWorld("world");
    3. int x = 1872;
    4. int y = 75;
    5. int z = -4187;
    6. for(int i = 0; i < 50; i++) {
    7. Location l = new Location(w, x, y, z);
    8. tLocs.add(l);
    9. x--;
    10. }
    11.  
     
  10. Offline

    xTrollxDudex

    Vincent1468
    Forgot pitch/yaw when making new location...
     
  11. Offline

    Dpasi314

    Vincent1468
    Yeah that's what it looks like (what xTrollxDudex said) I don't see you defining the yaw and pitch when you define Location.
     
  12. try Location(world,x,y,z,pitch,yaw) and get the pitch and yaw from the player, it should look better than normal
     
  13. Offline

    Techy4198

    I thought NoLiver92 said not to use pitch and yaw...
     
  14. yes, but he wants that the player can look around while getting teleported
    and if you teleport a player with Location(world,x,y,z) he always reset Yaw and Pitch,
    if you use Location(world,x,y,z,pitch,yaw) the player should be able to look around a bit
     
  15. Offline

    Vincent1468

    Techy4198
    I thought exactly the same, but i'll try what bluegru said!

    Edit: Just tried it like this:
    Code:java
    1.  
    2. l.setPitch(p.getLocation().getPitch());
    3. l.setYaw(p.getLocation().getYaw());
    4. p.teleport(l);
    5.  

    Now when the player gets teleported, his view still stays the same.
     
  16. Offline

    Techy4198

    um that makes no sense. if you keep setting the pitch and yaw then it will always stay the same during the sequence, but if you don't set it THEN he should be able to look around. exactly the opposite of what you said. if I am wrong and you are right, then teleportation was implemented by a crazy dude.
     
  17. Offline

    xTrollxDudex

    Vincent1468
    Use the pitch/yaw parameters when creating the location.
     
  18. whenever i teleport a player he looks at pitch 0, but if you get the pitch and yaw befor each teleport the player should have a bit time to look around befor getting teleported again
     
  19. Offline

    Vincent1468

    xTrollxDudex
    Just did that, no success. I'm creating all the locations in two loops, the two loops happen before the teleports.
     
  20. Then how do you teleport more than one time?
    The teleport (and the code to set the location) should be in one of them)
     
  21. Offline

    Vincent1468

    bluegru
    Here is exactly how I do it:
    Code:java
    1.  
    2. List<Location> tLocs = new ArrayList<Location>();
    3.  
    4. World w = Bukkit.getWorld("world");
    5. int x = 1872;
    6. int y = 75;
    7. int z = -4187;
    8. for(int i = 0; i < 50; i++) {
    9. Location l = new Location(w, x, y, z, p.getLocation().getPitch(), p.getLocation().getYaw());
    10. tLocs.add(l);
    11. x--;
    12. }
    13. for(int j = 0; j < 37; j++) {
    14. Location l = new Location(w, x, y, z, p.getLocation().getPitch(), p.getLocation().getYaw());
    15. tLocs.add(l);
    16. x--;
    17. z++;
    18. }
    19.  
    20. for(int i = 0; i < tLocs.size(); i += 6) {
    21. final Location l = tLocs.get(i);
    22. Bukkit.getScheduler().scheduleSyncDelayedTask(Test.getPlugin(), new Runnable() {
    23.  
    24. @Override
    25. public void run() {
    26. p.teleport(l);
    27. try {
    28. ParticleEffect.sendToLocation(ParticleEffect.EXPLODE, l.add(0, -1, 0), 0.25F, 0.25F, 0.25F, 0.25F, 16);
    29. } catch(Exception e) {
    30. e.printStackTrace();
    31. }
    32. }
    33.  
    34. }, i * 2);
    35. }
    36.  
     
  22. Offline

    xTrollxDudex

    Vincent1468
    Sorry, I couldnt help it. Yaw comes before pitch in location.
    PHP:
    Location l = new Location(worldxyzyawpitch);
     
  23. xTrollxDudex
    Both are float, so it should work
    or does it matter?
    does they have a different scale?
     
  24. Offline

    foodyling

    bluegru So if your yaw is 18, and your pitch is -50, but no worries, they are both int (they are actually floats), the constructor will take care of it for you and somehow magically find the difference?
     
  25. i don't know the scale of Yaw, i thought it is the same as Pitch,

     
  26. Offline

    xTrollxDudex

    bluegru
    Yea they are different scales.
     
  27. Offline

    Vincent1468

    bluegru
    xTrollxDudex

    Little mistake of mine, but I've switched them and still the same result.
    And really? This is kidna LQ in my eyes.
     
Thread Status:
Not open for further replies.

Share This Page