Shooting the player toward a location

Discussion in 'Plugin Development' started by JUSTCAMH, May 30, 2014.

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

    JUSTCAMH

    So I need to shoot the player to a location, which they aren't looking at. How would I make the player get shot in the direction of a block without changing their facing direction? Is this do-able?
    Help will be appreciated! ;)
     
  2. Offline

    Monkey_Swag

    JUSTCAMH show what code you have done first then we may be able to help :D
     
  3. Offline

    AoH_Ruthless

    JUSTCAMH
    Set their velocity to a direction, the direction being the vector of the block and the player.
     
  4. Offline

    JUSTCAMH

    Oh sorry here it is:
    Code:java
    1. public class ForceFieldListener implements Listener{
    2. ForceField ff;
    3. public ForceFieldListener(ForceField ff){
    4. this.ff = ff;
    5. }
    6. @EventHandler
    7. public void onPlayerMove(PlayerMoveEvent e){
    8. Player p = e.getPlayer();
    9. if(e.getTo().getBlock().getTypeId() == 34){
    10. //Shoot the player to e.getFrom()
    11. }
    12. }
    13. }


    AoH_Ruthless
    I know that but how to get the direction between two locations? I don't know how to get the direction of e.getFrom() from e.getTo().

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  5. Offline

    Antybarrel

    Couldnt you use vectors?
     
  6. Offline

    JUSTCAMH

  7. Offline

    Rocoty

    Google has the answer. <Edit by Moderator: Redacted bit url>
     
    Last edited by a moderator: Feb 12, 2017
  8. Offline

    renaud444

    You would do this:
    Subtract the "from" vector from the "to" vector, and set the player's velocity to the vector. I can create a quick test plugin for this. I'll post snippets if you'd like.

    EDIT: If it's a forcefield, wouldn't you just be able to cancel the event? If you don't want the player to be able to move into the forcefield block, cancelling the event should just move the player back to their previous position, like NoCheatPlus does when a player tries to use SurvivalFly hacks.
     
  9. Offline

    Commander9292

    JUSTCAMH
    If you don't want players to move into this "forcefield" block, why don't you just teleport them back to the "from" position instead of messing around with vectors and velocities.
     
  10. Offline

    JUSTCAMH

    cause I wanna make it like they go flying back and take damage to make them know not to touch a forcefield and beside it looks cooler
    I am making like a hunger games plugin and I want to make them go flying back when they touch the force field
     
Thread Status:
Not open for further replies.

Share This Page