Getting a random location around a set centre location within a radius

Discussion in 'Plugin Development' started by LoG_monster12345, Oct 27, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone,

    I'd be greatly appreciative if somebody could post a method which i can put in the paramaters: centrelocation (the centre location) and radius (the max amount of blocks away from the setlocation) which returns a new location within the range i set of the set centre location.

    This is for a custom spawner system i have, im trying to get a location within a range which is random just like how normal vanilla spawners work at determining where the mob should spawn around the 4 block radius of the default spawner.

    If this is not explained well enough please comment so i can fix it.

    Thanks, log!
     
  2. Offline

    Watto

    LoG_monster12345

    Posting a method isn't a very effective way of learning, even if you don't know how to do the radius there's plenty of methods all over the place which you can take and modify which is what i strong suggest you do.

    As for getting a random one it's as easy as having the blocks in an array of some kind and calling random.nextInt(array.size()-1);
     
  3. Offline

    Funergy

    LoG_monster12345 We do not spoonfeed you. We can only provide you the steps without code.
    You cannot learn from copying. So search some stuff on the internet about randoms and for loops,...
    and if you have a problem then, then you can post it here.

    BUT if you have some code please give it us and we'll help you out to fix the problem.

    EDIT: What Watto said
     
  4. Offline

    CraftCreeper6

    As Funergy & Watto said. You are not going to get a method here. Although if you want some links to some tutorials I'd be glad to link them :)
     
  5. Offline

    Syd

    How about good old Pythagoras?

    1. get a random number between -radius and +radius, that's your x difference (Random#nextInt(int))
    2. calculate the max difference for the z coordinate (z² = radius² - x²)
    3. get a random number between -z and +z, that's your z difference
    4. add x and z difference to your center location

    My explaination is longer than the actual code, so you should be able to reproduce it. ;)
     
    FroznMine likes this.
Thread Status:
Not open for further replies.

Share This Page