Stop players from entering a region..

Discussion in 'Plugin Development' started by Epicballzy, Jul 2, 2015.

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

    Epicballzy

    Hello everyone, I've been working on some project where players are able protect regions and whatever. I have that all set, but what I want to do is stop players from entering regions flagged as "do not enter".

    Now, I've already achieved this, but what I'm not able to figure out, is how to knockback a player when trying to enter a region while looking away from it.

    Here's an example if what's happening:


    when looking directly at the region, they get knocked back, but looking in the opposite direction, they're sucked in.

    Currently what I'm using to knock players back:
    Code:
    player.setVelocity(player.getLocation().getDirection().multiply(-.6));
    Is there another way to knock players back away from the region? Or is there some way to detect if a player is looking in the opposite direction of the region?

    Thanks!
     
  2. Offline

    caseif

    You'd essentially want to create a vector perpendicular to the edge of the region facing away from it. If it's a cuboid, I imagine this would entail determining which side of the cuboid the player intersected with and selecting a direction accordingly.
     
  3. Offline

    Epicballzy

    @caseif It's most likely going to always be a cuboid. I've managed to get all the different sides of the regions, but I don't know if the way I'm doing it is an efficient way.

    When a region is created, it loops through all the block locations in the region. it saves all the locations in 1 list, as you'd imagine. This would be used for things such as stopping players from building, etc.. While it's looping though the locations, it saves each side (as locations) in their own separate list.

    Then checking when a player moves into a region, check to see if one of the lists contains the players location.. If it does, push the player back opposite direction of the side they're on.

    This is the only way I could come up with. If you have a different way to work this out, or someone else, I'd like to hear :)

    Thanks for the tip!
     
  4. Offline

    caseif

    If it's always going to be a cuboid then it's very redundant to store every block in it. Rather, you should just store the minimum and maximum bounds on each axis, then compare locations to that to determine whether they're in the region.
     
  5. Offline

    mythbusterma

    @caseif

    The method Vector#isInAABB(Vector max, Vector min) is very handy for doing exactly that.
     
Thread Status:
Not open for further replies.

Share This Page