Getting any location 20 blocks away from a player but no further than 30?

Discussion in 'Plugin Development' started by TheSmallBones, Sep 4, 2013.

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

    TheSmallBones

    At the moment I'm generating an x and a z in between -30 to 20 and 20 to 30 and then adding it to the players cords, this is terrible though because its always diagonal from the player. I know there must be a better way to do this with vectors maybe?

    EDIT: Also, I'm getting the highest block at that location, so Y doesn't matter, just needs to be 20 blocks away from the player on their side, back, front, etc.
     
  2. The big question is, what is the end result you are going for? there might be a better way to do it then you imagine.
    So, what do you want to accomplish?
     
  3. Offline

    TheSmallBones

    My plugin has its own tick system which is every minute I broadcast an announcement, etc. What I'm trying to do is get my own spawning algorithm going so I can spawn certain mobs in the day. So every "tick" I'm getting all online players and spawning 5 mobs randomly around them from 20 to 30 away.
     
  4. the way i do it in my custom spawning: get the loaded chunks, get a random chunk, and a random location in that chunk. check for nearby players, if too close, try again. that way it checks all sides of the player, so to speak.
     
  5. Offline

    1Rogue

    I would just use the Random function and generate a number between 1-10, then add that number to 20. You can generate different numbers for the x and y, subtract/add them to the current player's location, and then run the new location through a method to check if the location is safe or not. (If not, teleport to a safe y or a new location entirely :p)
     
  6. Offline

    TheSmallBones

    That's basically the way I'm doing it right now. The problem is the mob will never spawn 20 blocks directly to their right or left. It'll always be diagonal.
     
  7. Offline

    1Rogue


    If you want it to only be directly right or left, (almost in a plus shape around the player), then simply only change the x or y at one time, not both. There is a chance, but if you think about it, that's a 1 in 100 chance every time they are spawned.
     
Thread Status:
Not open for further replies.

Share This Page